Sample questions
Question 1Easy
Which directive renders an element only when a condition is truthy and adds or removes it from the DOM?
- v-if
- v-show
- v-bind
- v-model
Answer: A. v-if
Explanation
v-if conditionally creates or destroys the element.
Step-by-step solution
- v-if adds the element to the DOM when the condition is truthy.
- It removes the element from the DOM when the condition is falsy.
- So v-if adds or removes the element (option A).
Why the other options are wrong
- B. v-show keeps the element in the DOM and only toggles its display.
- C. v-bind sets an attribute, not visibility.
- D. v-model binds form input values.
Tip: v-if removes the element; v-show hides it with CSS.
Question 2Easy
What is the shorthand for v-bind:href="url"?
- @href="url"
- :href="url"
- #href="url"
- $href="url"
Answer: B. :href="url"
Explanation
: is the shorthand for v-bind.
Step-by-step solution
- The full form is v-bind with a colon-separated argument, such as v-bind:href.
- The shorthand replaces the word v-bind with a single colon.
- So :href is the shorthand (option B).
Why the other options are wrong
- A. The at sign is the shorthand for v-on, not v-bind.
- C. A hash sign is not a Vue binding shorthand.
- D. A dollar sign is not a Vue binding shorthand.
Tip: Colon for bind, at sign for on.
Question 3Easy
Which syntax outputs a JavaScript expression's value as text in a Vue template?
- {{ expression }}
- <% expression %>
- ${ expression }
- [[ expression ]]
Answer: A. {{ expression }}
Explanation
Double curly braces (mustache syntax) interpolate text.
Step-by-step solution
- Write mustaches.
- Vue evaluates and escapes the result.
Why the other options are wrong
- B. EJS-style, not Vue.
- C. Template literal syntax, not Vue.
- D. [[ ]] is not Vue interpolation; Vue uses double curly braces.
Question 4Easy
Which directive is used to loop over an array in a template?
- v-loop
- v-each
- v-repeat
- v-for
Answer: D. v-for
Explanation
v-for="item in items" renders the element for each entry.
Step-by-step solution
- Vue has a built-in directive for rendering lists in templates.
- The directive is written as item in items.
- It renders the element once for each entry.
Why the other options are wrong
- A. v-loop is not a Vue directive.
- B. v-each is not a Vue directive.
- C. v-repeat is not a Vue directive.
Tip: Use v-for with item in items, and add a key to each rendered element.
Question 5Medium
What is the difference between v-show and v-if?
v-show removes the element from the DOM, while v-if hides it with CSS- They are identical except for the spelling of the name
v-show can only be applied to components, not plain elementsv-show toggles CSS display; v-if adds or removes the node
Answer: D. v-show toggles CSS display; v-if adds or removes the node
Explanation
v-show keeps the element in the DOM and toggles display; v-if has higher toggle cost but lower initial cost when false.
Step-by-step solution
- v-show always keeps the element in the DOM.
- It toggles the CSS display property.
- v-if adds or removes the element from the DOM instead.
- So v-show toggles CSS display and v-if adds or removes the node (option D).
Why the other options are wrong
- A. The two are reversed: v-show does not remove the element.
- B. They work differently in the DOM, not just in spelling.
- C. v-show works on plain elements as well as components.
Tip: Use v-show for frequent toggling and v-if when the element is rarely needed.
Question 6Medium
What is a valid way to bind several classes conditionally?
- :class="active: isOn, bold"
- class="{{ active }}"
- v-class="active"
- :class="{ active: isOn, 'text-bold': bold }"
Answer: D. :class="{ active: isOn, 'text-bold': bold }"
Explanation
:class accepts an object whose keys are class names and whose values are conditions.
Step-by-step solution
- Use v-bind on class.
- Pass an object of name to boolean.
Why the other options are wrong
- A. Not a valid object literal.
- B. Mustaches are not allowed in attributes.
- C. No v-class directive.
Question 7Medium
Which v-model modifier trims whitespace from user input?
- .lazy
- .number
- .once
- .trim
Answer: D. .trim
Explanation
.trim removes leading and trailing whitespace; .lazy syncs on change, .number casts to number.
Step-by-step solution
- The trim modifier removes leading and trailing whitespace from the input.
- The lazy modifier syncs on change instead of on each input.
- The number modifier casts the value to a number.
- So the whitespace modifier is .trim (option D).
Why the other options are wrong
- A. .lazy syncs on change; it does not trim.
- B. .number converts the value to a number; it does not trim.
- C. .once is not a v-model modifier.
Tip: v-model modifiers: .trim trims, .lazy waits for change, .number casts to a number.
Question 8Medium
What does v-model on a text input do?
- Two-way binding of input value and data
- Only binds data to the input, never the reverse
- Only listens to the input event without binding a value
- Validates the input and blocks invalid values automatically
Answer: A. Two-way binding of input value and data
Explanation
v-model binds the value and updates the data on input events.
Step-by-step solution
- v-model on a text input binds the input's value to the data.
- When the user types, the data is updated; when the data changes, the input updates.
- So it is two-way binding (option A).
Why the other options are wrong
- B. It binds both ways, not only from data to the input.
- C. It binds the value as well as listening to input events.
- D. v-model does not validate input.
Tip: v-model is two-way binding for form inputs.
Question 9Hard
Why is <template v-if> useful?
- It groups several siblings under one condition without adding a wrapper element
- It lazily loads the template file from the server only when the condition turns true
- It enables server rendering
- It caches the output forever
Answer: A. It groups several siblings under one condition without adding a wrapper element
Explanation
The <template> tag is a non-rendered wrapper that the compiler removes.
Step-by-step solution
- Put v-if on template.
- Children are shown or hidden together.
- No extra DOM node.
Why the other options are wrong
- B. It is not about loading.
- C. SSR is unrelated.
- D. No caching is done.
Question 10Hard
Can v-if and v-for be used on the same element, and what is the Vue 3 behavior?
- Yes, and
v-for has the higher priority of the two directives - No, combining them is always a compile-time error
- Yes, but
v-if runs first and cannot see the loop variable - Yes, and both are evaluated together with a shared scope
Answer: C. Yes, but v-if runs first and cannot see the loop variable
Explanation
In Vue 3, v-if is evaluated before v-for; wrap in a <template v-for> instead.
Step-by-step solution
- In Vue 3, v-if has higher priority than v-for on the same element.
- So v-if is evaluated first, and it cannot see the loop variable.
- To fix this, wrap the loop in a template element that has v-for, and put v-if inside.
- So the answer is option C.
Why the other options are wrong
- A. In Vue 3 v-if has the higher priority, not v-for.
- B. Combining them is allowed; it is a precedence issue, not a compile error.
- D. They are not evaluated together; v-if runs first.
Tip: Do not put v-if and v-for on the same element in Vue 3; move the condition to a wrapper.
Practise all 26 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 →