Vue.js / Nuxt.js

Vue Composables

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

20 câu hỏi phỏng vấn·
Mid-Level
1

What is a composable in Vue 3 and Nuxt 3?

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Vue.js / Nuxt.js cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí