Consider this Vue 3 component using the Composition API. What will be logged to the console when the button is clicked?
<template> <button @click="handleClick(5)">Click me</button> </template> <script setup> import { ref } from 'vue' function handleClick(num) { console.log(num * 2) } </script>
Remember how arguments are passed directly in Vue event handlers.
The handleClick function receives the argument 5 and logs 5 * 2 = 10.
In Vue 3, which of the following syntaxes correctly passes the argument 42 to the submitForm method when a button is clicked?
Vue event handlers use parentheses to pass arguments.
Option B uses the correct syntax to call submitForm with argument 42.
Given this Vue 3 component snippet, why does handleClick receive undefined instead of the expected number?
<template> <button @click="handleClick">Click me</button> </template> <script setup> function handleClick(num) { console.log(num) } </script>
Think about how Vue calls event handlers without explicit arguments.
Without parentheses, Vue calls handleClick with the event object by default. Since num expects a number but receives the event, and no argument is passed, it logs undefined.
count after clicking the button twice?Analyze this Vue 3 component. What will be the value of count after clicking the button two times?
<template> <button @click="increment(2)">Add 2</button> <p>{{ count }}</p> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment(amount) { count.value += amount } </script>
Each click adds 2 to count. Two clicks add 4 total.
Starting at 0, two clicks each add 2, so count becomes 4.
In Vue 3, you want to pass the native event object and a custom argument id to your handler handleClick. Which option achieves this correctly?
Use an inline arrow function to pass both event and custom arguments.
Option A uses an inline arrow function to pass the event and id explicitly. Option A is invalid syntax in Vue templates. Option A swaps argument order incorrectly. Option A passes only id.