From 7341f8994579b3ea78cee7cf594a8ea961080737 Mon Sep 17 00:00:00 2001 From: ktsn Date: Sun, 19 Feb 2017 23:50:53 +0900 Subject: [PATCH 1/2] Update getter docs #601 for ja --- docs/ja/getters.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/ja/getters.md b/docs/ja/getters.md index 6b4177a25..9420c316a 100644 --- a/docs/ja/getters.md +++ b/docs/ja/getters.md @@ -61,6 +61,21 @@ computed: { } ``` +関数を返り値にすることで、ゲッターに引数を渡すこともできます。これは特にストアの中の配列を検索する時に役立ちます: +```js +getters: { + // ... + getTodoById: (state, getters) => (id) => { + return getters.todos.find(todo => todo.id === id) + } +} +``` + +``` js +store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false } +``` + + ### `mapGetters` ヘルパー `mapGetters` ヘルパーはストアのゲッターをローカルの算出プロパティにマッピングさせます: From f7ec9df9ce8dd2b30c60e1b9f0681193a19fb683 Mon Sep 17 00:00:00 2001 From: ktsn Date: Sun, 19 Feb 2017 23:53:52 +0900 Subject: [PATCH 2/2] [docs] add a note that registerModule can receive an array of string #634 for ja --- docs/ja/modules.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/ja/modules.md b/docs/ja/modules.md index f819a9e16..647430e69 100644 --- a/docs/ja/modules.md +++ b/docs/ja/modules.md @@ -227,12 +227,18 @@ export function createPlugin (options = {}) { ストアが作られた**後**に `store.registerModule` メソッドを使って、モジュールを登録できます: ``` js +// `myModule` モジュールを登録します store.registerModule('myModule', { // ... }) + +// ネストされた `nested/myModule` モジュールを登録します +store.registerModule(['nested', 'myModule'], { + // ... +}) ``` -モジュールのステートには `store.state.myModule` でアクセスします。 +モジュールのステートには `store.state.myModule` と `store.state.nested.myModule` でアクセスします。 動的なモジュール登録があることで、他の Vue プラグインが、モジュールをアプリケーションのストアに付属させることで、状態の管理に Vuex を活用できることができます。例えば [`vuex-router-sync`](https://github.com/vuejs/vuex-router-sync) ライブラリは、動的に付属させたモジュール内部でアプリケーションのルーティングのステートを管理することで vue-router と vuex を統合しています。