Skip to content

Commit 1234464

Browse files
authored
[zh-cn] synced from #b206933 to #bb76bfd (#993)
* [zh-cn] synced from #b206933 to #bb76bfd * Update SUMMARY.md * Update modules.md
1 parent a8cfe75 commit 1234464

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

docs/zh-cn/SUMMARY.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# Vuex
22

3-
<!--email_off-->
4-
> 注意:本文档针对的是 vuex@2.x
5-
<!--/email_off-->
3+
> 注意:对于 TypeScript 用户来说 vuex@>= 3.0 依赖 vue@>=2.5,反之亦然。
64
7-
- [寻找 1.0 文档?](https://github.com/vuejs/vuex/tree/1.0/docs)
85
- [更新记录](https://github.com/vuejs/vuex/releases)
96
- [安装](installation.md)
107
- [Vuex 是什么?](intro.md)

docs/zh-cn/api.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const store = new Vuex.Store({ ...options })
1212

1313
- **state**
1414

15-
- 类型: `Object`
15+
- 类型: `Object | Function`
1616

17-
Vuex store 实例的根 state 对象。
17+
Vuex store 实例的根 state 对象。[详细介绍](state.md)
1818

19-
[详细介绍](state.md)
19+
如果你传入返回一个对象的函数,其返回的对象会被用做根 state。这在你想要重用 state 对象,尤其是重用 module 来说非常有用。[详细介绍](modules.md#模块重用)
2020

2121
- **mutations**
2222

@@ -158,10 +158,27 @@ const store = new Vuex.Store({ ...options })
158158

159159
通常用于插件。[详细介绍](plugins.md)
160160

161-
- **`registerModule(path: string | Array<string>, module: Module)`**
161+
- **`subscribeAction(handler: Function)`**
162+
163+
> 2.5.0 新增
164+
165+
订阅 store 的 action。`handler` 会在每个 action 分发的时候调用并接收 action 描述和当前的 store 的 state 这两个参数:
166+
167+
``` js
168+
store.subscribeAction((action, state) => {
169+
console.log(action.type)
170+
console.log(action.payload)
171+
})
172+
```
173+
174+
该功能常用于插件。[详细介绍](plugins.md)
175+
176+
- **`registerModule(path: string | Array<string>, module: Module, options?: Object)`**
162177

163178
注册一个动态模块。[详细介绍](modules.md#模块动态注册)
164179

180+
`options` 可以包含 `preserveState: true` 以允许保留之前的 state。用于服务端渲染。
181+
165182
- **`unregisterModule(path: string | Array<string>)`**
166183

167184
卸载一个动态模块。[详细介绍](modules.md#模块动态注册)

docs/zh-cn/modules.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ store.registerModule(['nested', 'myModule'], {
268268

269269
你也可以使用 `store.unregisterModule(moduleName)` 来动态卸载模块。注意,你不能使用此方法卸载静态模块(即创建 store 时声明的模块)。
270270

271+
在注册一个新 module 时,你很有可能想保留过去的 state,例如从一个服务端渲染的应用保留 state。你可以通过 `preserveState` 选项将其归档:`store.registerModule('a', module, { preserveState: true })`
272+
271273
### 模块重用
272274

273275
有时我们可能需要创建一个模块的多个实例,例如:

0 commit comments

Comments
 (0)