浏览代码

Update getter docs (#601)

* Update getter docs

Add possibility to return functions in getters (https://github.com/vuejs/vuex/issues/598)

* more detailed description

more detailed description and removed function syntax
mudrz 8 年之前
父节点
当前提交
4d796b0a1d
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      docs/en/getters.md

+ 15 - 0
docs/en/getters.md

@@ -61,6 +61,21 @@ computed: {
 }
 ```
 
+You can also pass arguments to getters by returning a function. This is particularly useful when you want to query an array in the store:
+```js
+getters: {
+  // ...
+  getTodoById: (state, getters) => (id) => {
+    return getters.todos.find(todo => todo.id === id)
+  }
+}
+```
+
+``` js
+store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }
+```
+
+
 ### The `mapGetters` Helper
 
 The `mapGetters` helper simply maps store getters to local computed properties: