Passing arguments to handlers
📖 Scenario: You are building a simple Vue 3 app where users can click buttons to greet different friends by name.
🎯 Goal: Create a Vue 3 component that shows three buttons labeled with friend names. When a button is clicked, it calls a handler function passing the friend's name as an argument. The handler then updates a message showing the greeting for that friend.
📋 What You'll Learn
Use Vue 3 Composition API with
<script setup>Create a reactive message variable to hold the greeting text
Create a handler function that accepts a name argument and updates the message
Add three buttons with friend names: 'Alice', 'Bob', and 'Charlie'
Pass the friend name as an argument to the click handler using
@click💡 Why This Matters
🌍 Real World
Passing arguments to event handlers is common in interactive web apps, like greeting users, selecting items, or filtering lists.
💼 Career
Understanding how to pass arguments to handlers is essential for building dynamic Vue components and handling user interactions effectively.
Progress0 / 4 steps