Vue.js Assignment– 2
Composition API Mastery
Basic Questions
- Create a component that uses setup() to return a greeting string and render it.
- Use ref() to build a click counter and display the current count.
- Use reactive() to manage a user object with name and email and render both.
- Create a computed() property that returns the uppercase version of a ref string.
- Use watch() to log changes to a ref counter whenever it updates.
- Build a form with reactive() state and bind inputs with v-model.
- Create a computed() that derives a full name from firstName and lastName refs.
- Watch a reactive() object’s specific field using a getter in watch().
- Implement onMounted() to fetch mock data (setTimeout) and render it.
- Use onUnmounted() to clean up a timer created in setup().
- Add onBeforeUpdate() to log when the component is about to re-render.
- Create a child component that accepts a prop and renders it using Composition API.
- Build a parent that passes a prop and updates it to see reactive re-renders.
- Use provide() in a parent to share a ref theme value.
- Use inject() in a child to read and display the shared theme.
- Create a minimal composable useCounter() that returns count and inc().
- Use useCounter() in a component and show that multiple instances are independent.
- Convert a small Options API component (data/methods) to Composition API.
- Add a computed() that depends on another computed() and verify re-computation.
- Use toRefs() on a reactive() object and bind fields to inputs without losing reactivity.
Intermediate Questions
- Create a useForm() composable that manages form state, validation, and reset.
- Build a component that uses watchEffect() to auto-run logic when dependencies change.
- Use shallowRef() to hold a large non-reactive object and show update behavior.
- Demonstrate readonly() by exposing a read-only version of reactive state to children.
- Use watch() with { immediate: true } to run a side effect on initial render.
- Implement debounced search inside setup() using customRef() for input.
- Add onBeforeMount() and onUpdated() hooks and log their call order.
- Create a tree of components using provide/inject to pass a settings object two levels deep.
- Write a useFetch(url) composable that returns { data, loading, error, reload } with abort support.
- Create a useInterval(ms) composable that starts/stops a timer with onMounted/onUnmounted.
- Build a tab UI that stores active tab in a ref; derive classes via computed().
- Use reactive() with nested objects and a deep watch() to persist state to localStorage.
- Implement onErrorCaptured() in a parent to catch a child’s rendering error.
- Migrate a medium Options API component (props, data, computed, methods, watch) to Composition API.
- Replace mixins in an existing component with a composable and prove no name collisions.
- Use provide() to expose a toggleTheme() function and call it from multiple children via inject().
- Build a usePagination() composable returning page, pageCount, next, prev, setPage.
- Optimize a list by memoizing expensive formatting inside computed() with primitive refs as deps.
- Create a component that conditionally uses watchPostEffect() vs watchEffect() and show the difference.
- Extract async form submission logic into a composable and reuse it in two components.
Advanced Questions
- Implement a useWebSocket(url) composable that manages connect/reconnect, exposes send() and reactive messages, and cleans up on unmount.
- Build a small app with two pages that share global reactive state via provide/inject without a store; include persistence on unload.
- Create a useField() composable (value, touched, errors, validators) and compose multiple fields into a useForm() for complex validation.
- Implement effectScope() to group multiple watchers/effects and dispose them together on route change.
- Build a performance benchmark comparing Options API vs Composition API with heavy computed chains and measure renders.
- Migrate a component that used two mixins to a single composable-based solution; remove naming conflicts and demonstrate improved types.
- Create a plugin that auto-registers a global custom directive and exposes a provide() API for default options.
- Implement a useAsyncQueue() composable that queues async tasks, exposes status, supports cancelation, and integrates with lifecycle hooks.
- Build a dashboard that uses multiple composables (useFetch, useInterval, usePagination) and prove reactivity isolation between widgets.
- Final Hands-on Project:
- Take a medium Options API feature (filters + table + detail modal)
- Migrate to Composition API with composables (useTable, useFilters, useModal)
- Share state via provide/inject where appropriate
- Add lifecycle hooks for data loading and cleanup
- Optimize with computed, watchEffect, and shallowRef for large payloads
- Document architecture, tradeoffs, and performance gains.