File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,21 @@ computed: {
6161}
6262```
6363
64+ 関数を返り値にすることで、ゲッターに引数を渡すこともできます。これは特にストアの中の配列を検索する時に役立ちます:
65+ ``` js
66+ getters: {
67+ // ...
68+ getTodoById : (state , getters ) => (id ) => {
69+ return getters .todos .find (todo => todo .id === id)
70+ }
71+ }
72+ ```
73+
74+ ``` js
75+ store .getters .getTodoById (2 ) // -> { id: 2, text: '...', done: false }
76+ ```
77+
78+
6479### ` mapGetters ` ヘルパー
6580
6681` mapGetters ` ヘルパーはストアのゲッターをローカルの算出プロパティにマッピングさせます:
Original file line number Diff line number Diff line change @@ -227,12 +227,18 @@ export function createPlugin (options = {}) {
227227ストアが作られた** 後** に ` store.registerModule ` メソッドを使って、モジュールを登録できます:
228228
229229``` js
230+ // `myModule` モジュールを登録します
230231store .registerModule (' myModule' , {
231232 // ...
232233})
234+
235+ // ネストされた `nested/myModule` モジュールを登録します
236+ store .registerModule ([' nested' , ' myModule' ], {
237+ // ...
238+ })
233239```
234240
235- モジュールのステートには ` store.state.myModule ` でアクセスします。
241+ モジュールのステートには ` store.state.myModule ` と ` store.state.nested.myModule ` でアクセスします。
236242
237243動的なモジュール登録があることで、他の Vue プラグインが、モジュールをアプリケーションのストアに付属させることで、状態の管理に Vuex を活用できることができます。例えば [ ` vuex-router-sync ` ] ( https://github.com/vuejs/vuex-router-sync ) ライブラリは、動的に付属させたモジュール内部でアプリケーションのルーティングのステートを管理することで vue-router と vuex を統合しています。
238244
You can’t perform that action at this time.
0 commit comments