Challenge - 5 Problems
Vue Setup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Vue 3 setup function render?
Consider this Vue 3 component using the setup function. What will be displayed on the page?
Vue
import { ref } from 'vue'; export default { setup() { const message = ref('Hello Vue 3!'); return { message }; }, template: `<p>{{ message }}</p>` };
Attempts:
2 left
💡 Hint
Remember that ref creates a reactive object and you can use it directly in the template.
✗ Incorrect
The ref 'message' holds the string 'Hello Vue 3!'. Returning it from setup exposes it to the template, which renders its value.
📝 Syntax
intermediate2:00remaining
Which setup function code is syntactically correct?
Identify the option that correctly defines a setup function returning a reactive count variable.
Attempts:
2 left
💡 Hint
The setup function must return an object with reactive properties for the template to access.
✗ Incorrect
Option D returns an object with the ref 'count', which Vue unwraps in the template. Other options return raw values or incorrect types.
❓ state_output
advanced2:00remaining
What is the value of 'count' after clicking the button twice?
Given this Vue 3 component, what will be the displayed count after two button clicks?
Vue
import { ref } from 'vue'; export default { setup() { const count = ref(0); function increment() { count.value++; } return { count, increment }; }, template: `<div><button @click="increment">Add</button><p>{{ count }}</p></div>` };
Attempts:
2 left
💡 Hint
Each click increases count by 1 starting from 0.
✗ Incorrect
The increment function adds 1 to count.value on each click. After two clicks, count is 2.
🔧 Debug
advanced2:00remaining
Why does this setup function cause a runtime error?
Examine the setup function below. Why will this code cause an error when the component renders?
Vue
import { ref } from 'vue'; export default { setup() { const name = ref('Alice'); return name; }, template: `<p>{{ name }}</p>` };
Attempts:
2 left
💡 Hint
Vue expects setup to return an object with keys for template bindings.
✗ Incorrect
Returning the ref directly means the template cannot find 'name' as a property, causing an error.
🧠 Conceptual
expert2:00remaining
Which statement about the Vue 3 setup function is true?
Select the correct statement about the setup function in Vue 3 components.
Attempts:
2 left
💡 Hint
Think about when setup runs and what it returns for the component.
✗ Incorrect
Setup runs early, before creation, and returns reactive data or methods for the template.