0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vuexの概要

0
Posted at

Vuexとは

コンポーネントが共有するデータの状態を、グローバルに管理するライブラリ。
storeと呼ばれるアプリケーションのデータの状態を保持するコンテナを使用して、
コンポーネントとデータの取得・保存を行う。

storeの4つの機能

state

アプリケーション全体のデータの状態を管理。
データの状態を確認したり、特定のデータの状態を見つけることができる。

mutations

stateの更新だけを行う。
actionsを通じてコミット(実行)される。
データの変更をデバッグするとき、mutationsのおかげでデバッグが容易になる。

actions

mutationsの呼び出しやAPIとの非同期通信を行う。
※actions自体は直接stateを変更できない。

getters

computedと同様の動きをして、stateの値を算出したものを返す場合に役立つ。
値がキャシュされ、gettersが依存しているstateが更新されない限り再評価しない。

相関図

Vuexの流れ.png

まとめ

必ず、mutationsを通じてstateを変更する。
4つの機能に分けたことで、データの流れを追いやすくデバッグのしやすい状態管理を実現できる。

参考教材
https://www.techpit.jp/courses/24

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?