yoklainterview sim

Frontend Vue Directives Templates Interview Questions

75 verified Frontend Vue Directives Templates interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Vue Directives TemplatesDifficulty 1
In Vue 3, what is the core difference between v-if and v-show?
  • av-if only works on components, v-show only works on plain HTML elements
  • bv-if adds/removes the element from the DOM
  • cv-show can use an else branch, v-if cannot
  • dThere is no difference — they are interchangeable aliases
Explanation:v-if conditionally renders (or destroys) the element and its component instance entirely — nothing exists in the DOM when false. v-show always renders the element and simply toggles the inline display: none CSS property, so the element stays in the DOM and keeps its component state.
Vue Directives TemplatesDifficulty 1
<template>
  <li v-for="item in items" :key="item.id">
    {{ item.name }}
  </li>
</template>

What does this template render?
  • aA single <li> containing the whole items array as JSON
  • bNothing, because v-for requires an index variable
  • cOne <li> per unique item.name value only
  • dOne <li> per element in items
Explanation:v-for="item in items" iterates over the items array, creating one <li> per element and binding item to each element in that iteration's scope, so {{ item.name }} shows each item's own name.
Vue Directives TemplatesDifficulty 1
What is :href="url" shorthand for in a Vue template?
  • av-bind:href="url"
  • bv-on:href="url"
  • cv-model:href="url"
  • dv-slot:href="url"
Explanation:The colon : prefix is shorthand for v-bind:, which binds an HTML attribute to a reactive expression. :href="url" and v-bind:href="url" are exactly equivalent.
Vue Directives TemplatesDifficulty 1
What is @click="handleClick" shorthand for in a Vue template?
  • av-bind:click="handleClick"
  • bv-if:click="handleClick"
  • cv-on:click="handleClick"
  • dv-for:click="handleClick"
Explanation:The @ prefix is shorthand for v-on:, which attaches an event listener. @click="handleClick" and v-on:click="handleClick" are exactly equivalent.
Vue Directives TemplatesDifficulty 1
<template>
  <p v-if="status === 'ok'">All good</p>
  <hr />
  <p v-else>Something's wrong</p>
</template>

What happens when this template renders?
  • aThe v-else correctly pairs with the v-if even with <hr /> between them
  • bThis is invalid — v-else must be on the element immediately following the v-if element
  • cBoth paragraphs render at the same time regardless of status
  • dVue silently ignores the v-else and only ever shows the first paragraph
Explanation:v-else (and v-else-if) must be placed on the sibling element that immediately follows the element carrying v-if. Inserting another element (like <hr />) between them breaks that adjacency, so Vue cannot associate the v-else with the v-if and this is invalid usage.
Vue Directives TemplatesDifficulty 1
Why does Vue recommend giving each v-for item a unique :key?
  • aIt gives Vue a stable identity per item
  • bIt is purely cosmetic and only affects browser DevTools display
  • cIt is required for v-for to compile at all — without it, the template throws a build error
  • dIt automatically sorts the list into ascending key order
Explanation:The key gives Vue's virtual DOM diffing algorithm a stable identity for each item, so when the list changes (reorder, insert, remove) Vue can match old nodes to new ones correctly instead of just patching them in index order — this preserves component state and avoids visual glitches.

Test yourself against the 2925-question Frontend bank.

Start interview