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 5 years have passed since last update.

vuexのgetters,state,mutations,actionsについて自分用メモ

Posted at

#vuexのgetters,state,mutations,actionsについて自分用メモ
最近vue.jsとvuexを使ったAPIのつなぎ部分を作成する機会があり、
vuexについて自分用メモを残すために書きます。

##actions
actionsはAPIとのデータのやり取りをする場合に使う。
例えば、DBからデータを取ってくる。
なんてときに使うAPIを叩くときにactionsを使うようにする。

##mutations
例えば、actionsで取ってきたデータをstateに入れる役割を持っている。
stateのデータを唯一変更することを許されている。
したがって、mutation以外でstateのデータを変更することは基本的にやらないほうが良い
mutation以外でデータを変更してしまうと、データの信頼性が損なわれてしまう。
あとわかりにくいソースになっちゃう。

##state
actionsでAPIから取ってきたデータを保存しておくオブジェクトです。

##getters
stateにあるデータを取ってくる処理を書く。
gettersがAPIを叩いてデータを取ってくる処理は書かないようにする。

自分用メモとして書いています。
間違った認識しているところがあれば、コメントいただけると幸いです。

##参考資料
vuex公式ドキュメント
https://vuex.vuejs.org/ja/

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?