Vue.js / Nuxt.js

Vue Composables

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

20 pertanyaan wawancara·
Mid-Level
1

What is a composable in Vue 3 and Nuxt 3?

Jawaban

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?

Jawaban

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?

Jawaban

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 pertanyaan wawancara

Kuasai Vue.js / Nuxt.js untuk wawancara berikutnya

Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.

Mulai gratis