Vue.js / Nuxt.js

Vue Components

Component lifecycle, props, events, slots, scoped styles, component communication, dynamic components

20 pertanyaan wawancara·
Junior
1

What is a Vue component?

Jawaban

A Vue component is a reusable Vue instance with a name. It encapsulates HTML, CSS and JavaScript into an independent logical unit. Components allow dividing the user interface into reusable and maintainable pieces. Each component has its own template, logic and styles, facilitating code organization and reusability.

2

How to declare props in a Vue 3 component with script setup?

Jawaban

In Vue 3 with script setup, defineProps() is a compiler macro that allows declaring props without explicit import. This macro automatically generates the necessary code and exposes props to the template. It supports TypeScript and JavaScript type validation, making the code more concise and type-safe than the Options API approach.

3

What is the function of the onMounted() hook in a component lifecycle?

Jawaban

The onMounted() hook executes after the component has been mounted to the DOM. This is the ideal moment to perform operations that require DOM access, like initializing third-party libraries, fetching data via API, or directly manipulating DOM elements. At this stage, the template is rendered and refs are accessible.

4

How does a child component emit an event to its parent component?

5

What are slots used for in a Vue component?

+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