Vue.js / Nuxt.js

Composition API

Setup function, ref, reactive, computed, watch, lifecycle hooks, composables, script setup

24 perguntas de entrevista·
Mid-Level
1

What is the Composition API in Vue 3?

Resposta

The Composition API is a new way to organize Vue component logic using composition functions instead of options (data, methods, computed). It allows grouping logic by feature rather than by option type, facilitating code reuse through composables. It also provides better TypeScript support and better organization for complex components.

2

What is the main function used in the Composition API to define a component's logic?

Resposta

The setup() function is the entry point of the Composition API. It executes before component creation, even before created(). It receives props and context as arguments and must return an object containing data and functions to expose to the template. It's in setup() where we use ref, reactive, computed, watch and the Composition API lifecycle hooks.

3

What is the main difference between ref() and reactive()?

Resposta

ref() creates a reactive reference for a primitive value or object, accessible via .value in script (but auto-unwrapped in templates). reactive() creates a reactive proxy for objects and arrays only, without requiring .value but loses reactivity if destructured. ref() is more versatile for primitives, reactive() is more natural for complex objects but requires toRef/toRefs for destructuring.

4

How to access the value of a ref in the setup() function?

5

How to create a computed property in the Composition API?

+21 perguntas de entrevista

Domine Vue.js / Nuxt.js para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis