This component uses a render function to show a greeting inside a styled section. It uses JavaScript variables and returns multiple elements inside an array.
Hello } uses JSX which is not default Vue render syntax. render() { return h(div, 'Hello') } misses quotes around 'div'. render() { return h('div', { text: 'Hello' }) } incorrectly uses an object with a text property.
Final Answer:
render() { return h('div', 'Hello') } -> Option D
Quick Check:
Tag as string + children string = correct syntax [OK]
Hint: Tag names must be strings in h calls [OK]
Common Mistakes:
Omitting quotes around tag names
Using JSX syntax without setup
Passing text inside an object instead of as child
3. What will the following Vue render function output?
A. Event handler key should be 'onClick' with capital C
B. Event handler key should be 'onclick' all lowercase
C. Event handler key should be 'onClick' but Vue expects 'onClick' as camelCase
D. Event handler key should be 'onClick' but Vue expects 'onClick' as 'onClick'
Solution
Step 1: Recall Vue event handler naming in render functions
Vue expects event handlers in render functions to use camelCase keys prefixed with 'on', like 'onClick'.
Step 2: Identify the incorrect key
The code uses 'onclick' with lowercase 'c', which Vue does not recognize as an event handler.
Final Answer:
Event handler key should be 'onClick' with capital C -> Option A
Quick Check:
Vue event keys are camelCase 'onClick' [OK]
Hint: Use camelCase event keys like 'onClick' in render functions [OK]
Common Mistakes:
Using lowercase event keys instead of camelCase
Confusing Vue event keys with JSX syntax
Assuming 'onclick' works like HTML attributes
5. How can you use a Vue render function to conditionally render a <span> with text 'Active' only if a signal isActive is true, otherwise render <span> with 'Inactive'?
hard
A. render() { if (isActive) return h('span', 'Active'); else return h('span', 'Inactive') }