Vue.js / Nuxt.js

Vue Advanced Patterns

Provide/inject, custom directives, render functions, JSX, teleport, suspense, async components

24 perguntas de entrevista·
Senior
1

What is the main purpose of provide/inject in Vue 3?

Resposta

Provide/inject allows passing data from a parent component to any descendant component without passing props through every intermediate level. This avoids 'props drilling' where props must be passed through multiple component levels that don't need them. Particularly useful for sharing global data like theme configuration or authentication state.

2

How to declare a value with provide in a component using the Composition API?

Resposta

In the Composition API, use the provide function with two arguments: a key (string or Symbol) and the value to provide. For example in setup. This value will be accessible to descendant components via inject. Using Symbols as keys guarantees uniqueness and avoids name collisions.

3

What is the main function of the Teleport directive in Vue 3?

Resposta

Teleport allows rendering a component's content in a different DOM node from its position in the Vue component tree. Typically used for modals, tooltips and notifications that need to be rendered at the document root to avoid z-index and CSS positioning issues. The component maintains its Vue context and can access parent data.

4

Which attribute is required to use Teleport in Vue 3?

5

What is a custom directive in Vue?

+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