Vue.js / Nuxt.js

Vue Advanced Patterns

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

24 คำถามสัมภาษณ์·
Senior
1

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

คำตอบ

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?

คำตอบ

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?

คำตอบ

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 คำถามสัมภาษณ์

เชี่ยวชาญ Vue.js / Nuxt.js สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี