\n\nBenefits of Composition API:\n• Better logic reuse and composition\n• More flexible code organization\n• Superior TypeScript integration\n• Smaller bundle size with tree-shaking"}},{"@type":"Question","name":"What is Vuex and how does it work? Explain with a complete example","acceptedAnswer":{"@type":"Answer","text":"Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all components.\n\nCore Concepts:\n1. State: Single source of truth - the data\n2. Getters: Computed properties for the store\n3. Mutations: Synchronous state changes (commit)\n4. Actions: Asynchronous operations (dispatch)\n5. Modules: For organizing large stores\n\nComplete Example:\n// store/index.js\nimport Vue from 'vue'\nimport Vuex from 'vuex'\n\nVue.use(Vuex)\n\nexport default new Vuex.Store({\n state: {\n count: 0,\n user: null\n },\n getters: {\n doubleCount: state => state.count * 2,\n isAuthenticated: state => !!state.user\n },\n mutations: {\n INCREMENT(state, payload) {\n state.count += payload.amount\n },\n SET_USER(state, user) {\n state.user = user\n }\n },\n actions: {\n incrementAsync({ commit }, payload) {\n setTimeout(() => {\n commit('INCREMENT', payload)\n }, 1000)\n },\n async login({ commit }, credentials) {\n const user = await api.login(credentials)\n commit('SET_USER', user)\n }\n },\n modules: {\n cart: cartModule,\n products: productsModule\n }\n})\n\nComponent Usage:\n// In component\ncomputed: {\n count() {\n return this.$store.state.count\n },\n doubleCount() {\n return this.$store.getters.doubleCount\n }\n},\nmethods: {\n increment() {\n this.$store.commit('INCREMENT', { amount: 1 })\n },\n incrementAsync() {\n this.$store.dispatch('incrementAsync', { amount: 1 })\n }\n}\n\nVuex Best Practices:\n• Use mutations for synchronous state changes\n• Use actions for asynchronous operations\n• Keep mutations simple and focused\n• Use getters for computed state\n• Organize large stores with modules"}},{"@type":"Question","name":"Explain Vue Router in depth including navigation guards and lazy loading","acceptedAnswer":{"@type":"Answer","text":"Vue Router is the official router for Vue.js applications, enabling Single Page Application (SPA) navigation.\n\nBasic Setup:\nimport Vue from 'vue'\nimport Router from 'vue-router'\nimport Home from './views/Home.vue'\n\nVue.use(Router)\n\nexport default new Router({\n mode: 'history', // Remove hash from URL\n routes: [\n {\n path: '/',\n name: 'home',\n component: Home\n },\n {\n path: '/about',\n name: 'about',\n component: () => import('./views/About.vue') // Lazy loading\n },\n {\n path: '/user/:id',\n name: 'user',\n component: User,\n props: true // Pass route params as props\n }\n ]\n})\n\nNavigation Guards:\n1. Global Guards:\nrouter.beforeEach((to, from, next) => {\n if (to.meta.requiresAuth && !isAuthenticated) {\n next('/login')\n } else {\n next()\n }\n})\n\n2. Per-Route Guards:\n{\n path: '/admin',\n component: Admin,\n beforeEnter: (to, from, next) => {\n if (!isAdmin()) next('/login')\n else next()\n }\n}\n\n3. In-Component Guards:\nexport default {\n beforeRouteEnter(to, from, next) {\n // Cannot access 'this'\n next(vm => {\n // Access component instance via 'vm'\n })\n },\n beforeRouteUpdate(to, from, next) {\n // React to route changes for same component\n this.fetchData(to.params.id)\n next()\n },\n beforeRouteLeave(to, from, next) {\n const answer = window.confirm('Do you really want to leave?')\n if (answer) next()\n else next(false)\n }\n}\n\nRoute Meta Fields:\n{\n path: '/profile',\n component: Profile,\n meta: {\n requiresAuth: true,\n title: 'User Profile'\n }\n}\n\nLazy Loading (Code Splitting):\nconst About = () => import('./views/About.vue')\n// Or with webpack magic comments\nconst About = () => import(/* webpackChunkName: \"about\" */ './views/About.vue')\n\nDynamic Route Matching:\n{\n path: '/user/:userId/post/:postId',\n component: UserPost\n}\n// Access via this.$route.params.userId and this.$route.params.postId"}},{"@type":"Question","name":"What are Vue directives? List and explain all commonly used directives","acceptedAnswer":{"@type":"Answer","text":"Directives are special attributes with the v- prefix that apply reactive behavior to the DOM.\n\nCommonly Used Directives:\n\n1. v-text: Updates element's textContent\n \n\n2. v-html: Updates element's innerHTML (use carefully - XSS risk)\n
\n\n3. v-show: Toggles display CSS property\nModal content that renders at body level
\n \nHello Vue!
\nBouncing text
\n{item.description}
\n {context.children}\nMaster 100+ comprehensive Vue.js questions covering Composition API, Reactivity (Proxy), Directives, Pinia, Vue Router, SSR, and Performance.
Vue.js is a progressive JavaScript framework for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable.
Key Features:
• Reactive Data Binding: Automatic synchronization between data and DOM
• Component System: Reusable, self-contained components with props and events
• Virtual DOM: Efficient rendering and performance optimization
• Directives: Special attributes (v-bind, v-model, v-for) for template functionality
• Computed Properties: Cached derived data that updates reactively
• Watchers: React to data changes with custom logic
• Lifecycle Hooks: Methods that execute at specific component stages
• Single-File Components: .vue files with template, script, and style in one file
• Vue Router: Official router for single-page applications
• Vuex: State management pattern + library
• Vue DevTools: Browser extension for debugging Vue applications
Vue is particularly known for its gentle learning curve, excellent documentation, and flexibility.
The Vue instance is the root of every Vue application, created with the Vue constructor.
Lifecycle Hooks (Vue 2):
1. beforeCreate: Called immediately after instance initialization, before data observation
2. created: After instance creation - data is reactive, computed properties are set up
3. beforeMount: Before initial render and when the template is compiled
4. mounted: After the instance has been mounted and the DOM is rendered
5. beforeUpdate: When data changes, before the DOM is re-rendered and patched
6. updated: After data changes and the DOM has been re-rendered
7. beforeDestroy: Before instance is destroyed - instance is still fully functional
8. destroyed: After instance is destroyed - all directives unbound, event listeners removed
Vue 3 Composition API Lifecycle:
• setup(): Replaces beforeCreate and created
• onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted
Example:
new Vue({
el: '#app',
data: { message: 'Hello Vue!' },
beforeCreate() { console.log('beforeCreate') },
created() { console.log('created') },
mounted() { console.log('mounted - DOM ready') }
})
v-if vs v-show:
v-if:
• Conditionally renders the element in the DOM
• Adds/removes element completely from DOM
• Supports v-else and v-else-if
• Higher toggle cost but better initial load performance
• Use when: The condition changes infrequently, or you need conditional rendering with else blocks
v-show:
• Always renders the element in the DOM
• Uses CSS display property to show/hide (display: none)
• Does not support else blocks
• Higher initial render cost but better toggle performance
• Use when: You need frequent toggling, or the content is expensive to re-render
Example:
<!-- v-if - element removed from DOM when false -->
<div v-if="isVisible">This may not be in DOM</div>
<div v-else>Else content</div>
<!-- v-show - always in DOM, just hidden -->
<div v-show="isVisible">Always in DOM, just hidden</div>
Performance Considerations:
• Use v-if when the condition is unlikely to change at runtime
• Use v-show for elements that need to be toggled frequently
• v-if has higher toggle costs, v-show has higher initial render costs
Proven methodologies and frameworks to succeed in technical and architecture rounds.
When responding to architectural or situational questions, structure your answer using Situation, Technical Constraint, Action, and Measurable Result. Rather than jumping straight to syntax, articulate the business problem, why certain patterns (e.g. caching, queuing, immutability) were selected over alternatives, and what latency or throughput improvements were achieved.
Senior interviewers evaluate how you weigh trade-offs. Always explain why you chose an approach: e.g., memory overhead vs CPU cycle speed, consistency vs availability (CAP theorem), or normalized schemas vs denormalized fast reads. Stating the drawbacks of your own proposal demonstrates maturity and production experience.
In live-coding rounds, communicate your thinking aloud before typing. State edge cases explicitly: null or undefined inputs, extreme boundary values, concurrency races, and network timeouts. Writing modular, well-named functions with deterministic unit tests separates junior candidates from staff-level engineers.
Avoid reciting memorized definitions without practical context. Never dismiss non-functional requirements such as security (CSRF, injection, token rotation), observability (logging, metrics), and accessibility (ARIA, semantic standards). Always ask clarifying scope questions before writing complex implementations.
Hand-picked utilities and calculators related to this tool.