File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,21 @@ computed: {
61
61
}
62
62
```
63
63
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
+
64
79
### ` mapGetters ` ヘルパー
65
80
66
81
` mapGetters ` ヘルパーはストアのゲッターをローカルの算出プロパティにマッピングさせます:
Original file line number Diff line number Diff line change @@ -227,12 +227,18 @@ export function createPlugin (options = {}) {
227
227
ストアが作られた** 後** に ` store.registerModule ` メソッドを使って、モジュールを登録できます:
228
228
229
229
``` js
230
+ // `myModule` モジュールを登録します
230
231
store .registerModule (' myModule' , {
231
232
// ...
232
233
})
234
+
235
+ // ネストされた `nested/myModule` モジュールを登録します
236
+ store .registerModule ([' nested' , ' myModule' ], {
237
+ // ...
238
+ })
233
239
```
234
240
235
- モジュールのステートには ` store.state.myModule ` でアクセスします。
241
+ モジュールのステートには ` store.state.myModule ` と ` store.state.nested.myModule ` でアクセスします。
236
242
237
243
動的なモジュール登録があることで、他の Vue プラグインが、モジュールをアプリケーションのストアに付属させることで、状態の管理に Vuex を活用できることができます。例えば [ ` vuex-router-sync ` ] ( https://github.com/vuejs/vuex-router-sync ) ライブラリは、動的に付属させたモジュール内部でアプリケーションのルーティングのステートを管理することで vue-router と vuex を統合しています。
238
244
You can’t perform that action at this time.
0 commit comments