You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/vuex/api.md
+52-52Lines changed: 52 additions & 52 deletions
Original file line number
Diff line number
Diff line change
@@ -12,62 +12,62 @@ import Vuex from 'vuex'
12
12
conststore=newVuex.Store({ ...options })
13
13
```
14
14
15
-
### Vuex.Store Constructor Options
15
+
### Vuex.Store 构造选项
16
16
17
17
-**state**
18
18
19
-
-type:`Object`
19
+
-类型:`Object`
20
20
21
-
The root state object for the Vuex store.
21
+
Vuex store 的根state对象。
22
22
23
23
[Details](state.md)
24
24
25
25
-**mutations**
26
26
27
-
-type:`{ [type: string]: Function }`
27
+
-类型:`{ [type: string]: Function }`
28
28
29
-
Register mutations on the store. The handler function always receives `state` as the first argument (will be module local state if defined in a module), and receives a second `payload` argument if there is one.
29
+
在 store 上注册 mutation,Handler function总是接收 state 作为第一个参数(如果定义在模块中,则作为模块的本地状态),如果有则接收 payload 作为第二个参数。
30
30
31
-
[Details](mutations.md)
31
+
[详细介绍](mutations.md)
32
32
33
33
-**actions**
34
34
35
-
-type:`{ [type: string]: Function }`
35
+
-类型:`{ [type: string]: Function }`
36
36
37
-
Register actions on the store. The handler function receives a `context` object that exposes the following properties:
37
+
在 store 上注册 action。Handler function接收一个 context 对象,这个对象提供以下属性:
38
38
39
39
```js
40
40
{
41
-
state, //same as store.state, or local state if in modules
42
-
rootState, //same as store.state, only in modules
43
-
commit, //same as store.commit
44
-
dispatch, //same as store.dispatch
45
-
getters //same as store.getters
41
+
state, //等同于 store.state,如果在模块中则是本地状态
42
+
rootState, //等同于 store.state,模块中才有
43
+
commit, //等同于 store.commit
44
+
dispatch, //等同于 store.dispatch
45
+
getters //等同于 store.getters
46
46
}
47
47
```
48
48
49
-
[Details](actions.md)
49
+
[详细介绍](actions.md)
50
50
51
51
-**getters**
52
52
53
-
-type:`{ [key: string]: Function }`
53
+
-类型:`{ [key: string]: Function }`
54
54
55
-
Register getters on the store. The getterfunction receives the following arguments:
55
+
在 store 上注册 getter,getter 方法接收一下参数:
56
56
57
57
```
58
-
state, //will be module local state if defined in a module.
59
-
getters, //same as store.getters
60
-
rootState //same as store.state
58
+
state, //如果在模块中定义则为模块的本地状态
59
+
getters, //等同于 store.getters
60
+
rootState //等同于 store.state
61
61
```
62
-
Registered getters are exposed on `store.getters`.
62
+
注册的 getter 被暴露在 store.getters。
63
63
64
-
[Details](getters.md)
64
+
[详细介绍](getters.md)
65
65
66
66
-**modules**
67
67
68
-
- type: `Object`
68
+
-类型:`Object`
69
69
70
-
An object containing sub modules to be merged into the store, in the shape of:
70
+
包含了子模块的对象,会被合并到 store,形如:
71
71
72
72
``` js
73
73
{
@@ -82,64 +82,64 @@ const store = new Vuex.Store({ ...options })
82
82
}
83
83
```
84
84
85
-
Each module can contain `state` and `mutations` similar to the root options. A module's state will be attached to the store's root state using the module's key. A module's mutations and getters will only receives the module's local state as the first argument instead of the root state, and module actions' `context.state` will also point to the local state.
85
+
每个模块可以包含 state 和 mutations,就像根模块的配置。一个模块的状态使用模块的 key 附加到 store 的根状态上。模块的 mutation 和 getter 将接收 module 的本地状态作为第一个参数,而不是根状态,并且模块 action 的 context.state 也指向本地状态。
86
86
87
-
[Details](modules.md)
87
+
[详细介绍](modules.md)
88
88
89
89
-**plugins**
90
90
91
-
- type:`Array<Function>`
91
+
-类型:`Array<Function>`
92
92
93
-
An array of plugin functions to be applied to the store. The plugin simply receives the store as the only argument and can either listen to mutations (for outbound data persistence, logging, or debugging) or dispatch mutations (for inbound data e.g. websockets or observables).
93
+
一个插件方法的数组被应用于 store 上。这些插件直接接收 store 作为唯一参数,也可以监听 mutation(用于外部地数据持久化、记录或调试)或者提交 mutation (用于内部数据,例如 websocket 或 某些观察者)。
94
94
95
-
[Details](plugins.md)
95
+
[详细介绍](plugins.md)
96
96
97
97
-**strict**
98
98
99
-
- type:`Boolean`
100
-
- default:`false`
99
+
-类型:`Boolean`
100
+
-默认值:`false`
101
101
102
-
Force the Vuex store into strict mode. In strict mode any mutations to Vuex state outside of mutation handlers will throw an Error.
102
+
强制 Vuex store 进入严格模式,在严格模式下,在 mutation 处理器以外修改 Vuex state 则会抛出错误。
Reactively watch a getter function's return value, and call the callback when the value changes. The getter receives the store's state as the only argument. Accepts an optional options object that takes the same options as Vue's `vm.$watch` method.
136
+
响应式的监测一个 getter 方法的返回值,当值改变时调用回调。getter 接收 store 的 state 作为唯一参数。接收类似 vm.$watch 方法的参数的可选对象。
137
137
138
-
To stop watching, call the returned handle function.
138
+
要停止检测,调用该方法的返回值 (watch 的返回值是个方法)。
139
139
140
140
-**`subscribe(handler: Function)`**
141
141
142
-
Subscribe to store mutations. The `handler` is called after every mutaiton and receives the mutation descriptor and post-mutation state as arguments:
0 commit comments