Explain the difference between v-show and v-if directives.
Instruction: Compare and contrast the v-show and v-if directives in Vue.js.
Context: This question is designed to test the candidate's understanding of conditional rendering in Vue.js and the practical differences between using v-show and v-if.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
v-if conditionally creates and destroys a rendered branch. When initially false, that branch is not mounted. Turning it off unmounts its child components, and turning it on creates new instances with their normal initialization behavior.
v-show keeps the element mounted and toggles its display style. Component state, watchers and external work can remain active while the element is hidden...