Complete the code to create a simple Vue component using JSX that renders a <div> with text.
import { defineComponent } from 'vue'; export default defineComponent({ setup() { return () => <[1]>Hello Vue JSX!</[1]>; } });
The JSX code returns a div element with the text inside. Using div is correct here.
Complete the code to define a JSX render function that returns a button with a click event handler.
import { defineComponent } from 'vue'; export default defineComponent({ setup() { const handleClick = () => alert('Clicked!'); return () => <button on[1]={handleClick}>Click me</button>; } });
In Vue JSX, event handlers use camelCase after on, like onClick. Fill Click to form onClick={handleClick}.
Fix the error in the JSX code that tries to render a list of items inside a Vue component.
import { defineComponent } from 'vue'; export default defineComponent({ setup() { const items = ['apple', 'banana', 'cherry']; return () => ( <ul> {items.[1](item => <li key={item}>{item}</li>)} </ul> ); } });
The map method transforms each item into a JSX element. Using forEach or others won't return the new array needed for rendering.
Fill both blanks to create a reactive state and update it on button click in a Vue JSX component.
import { defineComponent, [1] } from 'vue'; export default defineComponent({ setup() { const count = [2](0); const increment = () => count.value++; return () => <button onClick={increment}>Count: {count.value}</button>; } });
Vue uses ref to create a reactive primitive value. Importing ref and calling ref(0) creates a reactive count.
Fill all three blanks to create a Vue JSX component that conditionally renders text based on a signal.
import { defineComponent, [1] } from 'vue'; export default defineComponent({ setup() { const isVisible = [2](true); return () => ( <div> {isVisible.value ? <p>[3]</p> : null} </div> ); } });
We import and use ref to create a reactive boolean. The JSX conditionally renders the text Visible! when isVisible.value is true.