Sample questions
Question 1Easy
What does <script setup> expose to the template automatically?
- Only returned values, exactly like a setup function that must return an object
- Nothing
- Only props
- Top-level variables, functions and imports
Answer: D. Top-level variables, functions and imports
Explanation
The compiler makes top-level bindings available without a return statement.
Step-by-step solution
- Declare a const.
- Use it in the template.
Why the other options are wrong
- A. No return needed.
- B. The template can use them.
- C. Not only props.
Question 2Easy
What is the second argument of inject('key', 'fallback')?
- A type check that makes Vue warn when the provided value has a different type
- A required flag
- A scope name
- A default value used when nothing is provided
Answer: D. A default value used when nothing is provided
Explanation
Without a provider and a default, Vue warns that injection was not found.
Step-by-step solution
- Look up key.
- Use default if missing.
Why the other options are wrong
- A. The second argument is a fallback value; Vue does no type check with it.
- B. The second argument is a default value, not a required flag.
- C. The second argument is a fallback value, not a scope name.
Question 3Easy
What does <script setup> provide?
- A way to write only Options API components
- A server-only script that never runs in the browser
- A global plugin registry for third-party libraries
- Compile-time sugar for the Composition API in SFCs
Answer: D. Compile-time sugar for the Composition API in SFCs
Explanation
Top-level bindings in <script setup> are exposed to the template.
Step-by-step solution
- Script setup is a compile-time shorthand for the Composition API.
- Top-level bindings in it are exposed to the template automatically.
- So it gives compile-time sugar for the Composition API in single-file components (option D).
Why the other options are wrong
- A. It is used for Composition API code, not only Options API.
- B. It runs in the browser like any component script; it is not server-only.
- C. It does not register plugins; that is done with app.use.
Tip: Use script setup for new single-file components.
Question 4Medium
How do you get a template ref to an element with ref="box" in <script setup>?
- document.getElementById('box')
- this.$refs only
- const box = ref(null) — same name as the template ref
- useRef('box')
Answer: C. const box = ref(null) — same name as the template ref
Explanation
A ref variable with the same name is bound automatically and filled after mount.
Step-by-step solution
- Declare ref(null).
- Use name in template.
- Read it in onMounted.
Why the other options are wrong
- A. Works but bypasses Vue.
- B. Options API style.
- D. React API.
Question 5Medium
What is a composable in Vue?
- A component that has a script and style but no template
- A custom directive registered on the app instance
- A function that reuses stateful logic via Composition API
- A module in the older Vuex store
Answer: C. A function that reuses stateful logic via Composition API
Explanation
Composables, by convention named useXxx, return refs and functions for reuse.
Step-by-step solution
- A composable is a function that holds reusable stateful logic.
- It uses the Composition API, such as refs and computed values.
- By convention it is named useSomething and returns refs and functions (option C).
Why the other options are wrong
- A. A component with a script and style but no template is not a composable.
- B. A custom directive is a separate feature, not a composable.
- D. A Vuex module is a store module, not a composable.
Tip: Name composables with a use prefix and return refs and functions from them.
Question 6Medium
What is a composable, by convention?
- A function using Composition API that encapsulates reusable stateful logic, named useXxx
- A mixin object with data and methods that is merged into each component that uses it
- A global plugin installed with app.use
- A component compiled to a class
Answer: A. A function using Composition API that encapsulates reusable stateful logic, named useXxx
Explanation
Composables like useMouse() return refs and functions that components can share.
Step-by-step solution
- Write a function.
- Use refs inside.
- Return state and methods.
Why the other options are wrong
- B. Mixins are the Options API approach.
- C. Plugins are different.
- D. Components are not required.
Question 7Medium
What does defineProps<{ title: string }>() demonstrate?
- Type-based props declaration in
<script setup> - Runtime-only validation with no type information
- A global component registration with TypeScript
- Typing the events a component emits
Answer: A. Type-based props declaration in <script setup>
Explanation
The generic argument declares props types and the compiler derives runtime options.
Step-by-step solution
- DefineProps with a type argument declares the props in TypeScript types.
- The compiler derives the runtime prop options from that type.
- So it demonstrates type-based props declaration in script setup (option A).
Why the other options are wrong
- B. The type argument provides type information, so it is not runtime-only.
- C. Global component registration is a separate concern.
- D. Events are typed with defineEmits, not defineProps.
Tip: Use type-based defineProps for typed props without writing runtime options by hand.
Question 8Medium
What does toRef(state, 'count') return?
- A ref linked to the property of the reactive object
- A copy of the number at that moment, which no longer follows later changes
- A computed
- A new reactive object
Answer: A. A ref linked to the property of the reactive object
Explanation
Writing to the ref updates state.count and vice versa.
Step-by-step solution
- Pick one property.
- Get a linked ref.
Why the other options are wrong
- B. It stays synced.
- C. It is a ref.
- D. It is a ref.
Question 9Hard
What is the effect of toRaw(proxy)?
- Creates a deep clone of the reactive object
- Makes the plain object reactive again
- Freezes the object so it can never change
- Returns the original object; mutating it triggers no updates
Answer: D. Returns the original object; mutating it triggers no updates
Explanation
toRaw returns the original object; mutating it does not trigger updates.
Step-by-step solution
- ToRaw takes a reactive proxy and returns the original object underneath.
- Changes made to that original object do not go through the proxy.
- So mutating it triggers no updates (option D).
Why the other options are wrong
- A. ToRaw returns the same object, not a deep clone.
- B. ToRaw removes reactivity; it does not add it.
- C. ToRaw does not freeze the object.
Tip: Use toRaw only for reads or for passing a plain object where reactivity is not needed.
Question 10Hard
Why is calling a composable inside an if or after await in setup risky?
- Composables cannot use if statements because hooks must always run unconditionally
- Lifecycle hooks and watchers need an active component instance, which is lost after await
- It makes the app slower
- Vue forbids async
Answer: B. Lifecycle hooks and watchers need an active component instance, which is lost after await
Explanation
Instance context is tracked synchronously; <script setup> handles top-level await specially, but nested composables do not.
Step-by-step solution
- Context set during setup.
- After await it is gone.
Why the other options are wrong
- A. Conditions are allowed if sync.
- C. Not about speed.
- D. Async functions are allowed.
Practise all 16 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →