Vue.js / Nuxt.js

Vue Composables

Creating composables, reusable logic, useState, useRoute, useRouter, custom composables patterns

20 interview questions·
Mid-Level
1

What is a composable in Vue 3 and Nuxt 3?

Answer

A composable is a function that encapsulates reusable logic using Vue's Composition API. Composables allow sharing state and effects between components without resorting to mixins. By convention, a composable's name always starts with the use prefix, which makes them easy to identify in the code.

2

What is the recommended naming convention for composables?

Answer

Composables should always start with the use prefix followed by a descriptive name in camelCase. This convention allows quickly identifying composables in the code and distinguishing them from ordinary utility functions. For example, useCounter, useFetch, or useAuth are appropriate names for composables.

3

Where should composables be placed in a Nuxt 3 project?

Answer

Composables should be placed in the composables directory at the root of the project. Nuxt 3 automatically imports all files from this directory, which allows using composables without needing to import them manually. This auto-import improves developer experience and reduces boilerplate code.

4

What is the main advantage of useState over ref in Nuxt 3?

5

How to access the current route parameters in a Nuxt composable?

+17 interview questions

Master Vue.js / Nuxt.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free