Complete the code to define a simple functional component in Vue 3.
<script setup> import { [1] } from 'vue' const HelloWorld = [1](() => { return <h1>Hello, Vue!</h1> }) </script>
In Vue 3, defineComponent is used to define components, including functional ones.
Complete the code to accept props in a Vue functional component.
<script setup> import { defineComponent } from 'vue' const Greeting = defineComponent((props) => { return <p>Hello, {props.[1]!</p> }) </script>
The prop name is used to display the greeting message.
Fix the error in the functional component that returns multiple root elements.
<script setup> import { defineComponent } from 'vue' const MultiRoot = defineComponent(() => { return ( <div> <h1>Title</h1> [1] </div> ) }) </script>
Vue requires a single root element, so wrapping multiple elements in a <div> fixes the error.
Fill both blanks to create a functional component that emits an event on button click.
<script setup> import { defineComponent, [1] } from 'vue' const Clicker = defineComponent((props, { [2] }) => { const handleClick = () => { emit('clicked') } return <button onClick={handleClick}>Click me</button> }) </script>
The emit function is used to send events, and it is accessed via defineEmits in Vue 3 functional components.
Fill all three blanks to create a functional component that uses a ref and updates it on button click.
<script setup> import { [1], defineComponent } from 'vue' const Counter = defineComponent(() => { const count = [2](0) const increment = () => { count.value [3] 1 } return <button onClick={increment}>Count: {count.value}</button> }) </script>
ref creates a reactive value, and += increments it correctly.