Vue.js / Nuxt.js

Vuex (Legacy)

Vuex 4 store, state, mutations, actions, getters, modules, namespacing, migration to Pinia

15 面接問題·
Mid-Level
1

What is a Vuex store?

回答

A Vuex store is a centralized container that manages the global state of a Vue application. It allows sharing data between multiple components without manually passing props through the component tree. The store ensures that state can only be modified predictably through mutations, which simplifies debugging and maintenance of complex applications.

2

What is the main difference between mutations and actions in Vuex?

回答

Mutations are synchronous and directly responsible for modifying state, while actions are asynchronous and can contain complex business logic before committing mutations. Actions are ideal for API calls, timers, or any asynchronous operations, as they can wait for results before modifying state via mutations. This separation ensures that state modifications remain traceable in Vue DevTools.

3

What are getters used for in a Vuex store?

回答

Getters in Vuex work like computed properties for the store. They allow computing derived values from state without duplicating logic across multiple components. Getters are cached and only recalculate when their dependencies change, providing good performance. They are perfect for filtering, sorting, or transforming state data before exposing it to components.

4

How to access Vuex state from a Vue component?

5

Why use actions instead of mutations for API calls in Vuex?

+12 面接問題

次の面接に向けてVue.js / Nuxt.jsをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める