Skip to content

Commit f83de08

Browse files
authored
Merge pull request #181 from menpuji/2.0-cn
vuex api 部分翻译
2 parents 391914f + 0cb0da0 commit f83de08

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

src/vuex/api.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,62 @@ import Vuex from 'vuex'
1212
const store = new Vuex.Store({ ...options })
1313
```
1414

15-
### Vuex.Store Constructor Options
15+
### Vuex.Store 构造选项
1616

1717
- **state**
1818

19-
- type: `Object`
19+
- 类型: `Object`
2020

21-
The root state object for the Vuex store.
21+
Vuex store 的根state对象。
2222

2323
[Details](state.md)
2424

2525
- **mutations**
2626

27-
- type: `{ [type: string]: Function }`
27+
- 类型: `{ [type: string]: Function }`
2828

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 作为第二个参数。
3030

31-
[Details](mutations.md)
31+
[详细介绍](mutations.md)
3232

3333
- **actions**
3434

35-
- type: `{ [type: string]: Function }`
35+
- 类型: `{ [type: string]: Function }`
3636

37-
Register actions on the store. The handler function receives a `context` object that exposes the following properties:
37+
store 上注册 action。Handler function接收一个 context 对象,这个对象提供以下属性:
3838

3939
``` js
4040
{
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
4646
}
4747
```
4848

49-
[Details](actions.md)
49+
[详细介绍](actions.md)
5050

5151
- **getters**
5252

53-
- type: `{ [key: string]: Function }`
53+
- 类型: `{ [key: string]: Function }`
5454

55-
Register getters on the store. The getter function receives the following arguments:
55+
store 上注册 getter,getter 方法接收一下参数:
5656

5757
```
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
6161
```
62-
Registered getters are exposed on `store.getters`.
62+
注册的 getter 被暴露在 store.getters
6363

64-
[Details](getters.md)
64+
[详细介绍](getters.md)
6565

6666
- **modules**
6767

68-
- type: `Object`
68+
- 类型: `Object`
6969

70-
An object containing sub modules to be merged into the store, in the shape of:
70+
包含了子模块的对象,会被合并到 store,形如:
7171

7272
``` js
7373
{
@@ -82,64 +82,64 @@ const store = new Vuex.Store({ ...options })
8282
}
8383
```
8484

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+
每个模块可以包含 statemutations,就像根模块的配置。一个模块的状态使用模块的 key 附加到 store 的根状态上。模块的 mutation 和 getter 将接收 module 的本地状态作为第一个参数,而不是根状态,并且模块 action 的 context.state 也指向本地状态。
8686

87-
[Details](modules.md)
87+
[详细介绍](modules.md)
8888

8989
- **plugins**
9090

91-
- type: `Array<Function>`
91+
- 类型: `Array<Function>`
9292

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 或 某些观察者)。
9494

95-
[Details](plugins.md)
95+
[详细介绍](plugins.md)
9696

9797
- **strict**
9898

99-
- type: `Boolean`
100-
- default: `false`
99+
- 类型: `Boolean`
100+
- 默认值: `false`
101101

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 则会抛出错误。
103103

104-
[Details](strict.md)
104+
[详细介绍](strict.md)
105105

106106
### Vuex.Store Instance Properties
107107

108108
- **state**
109109

110-
- type: `Object`
110+
- 类型: `Object`
111111

112112
The root state. Read only.
113113

114114
- **getters**
115115

116-
- type: `Object`
116+
- 类型: `Object`
117117

118-
Exposes registered getters. Read only.
118+
暴露注册的 getter,只读。
119119

120-
### Vuex.Store Instance Methods
120+
### Vuex.Store 实例方法
121121

122-
- **`commit(type: string, payload?: any) | commit(mutation: Object)`**
122+
- **`commit(类型: string, payload?: any) | commit(mutation: Object)`**
123123

124-
Commit a mutation. [Details](mutations.md)
124+
提交一个 mutation. [详细介绍](mutations.md)
125125

126126
- **`dispatch(type: string, payload?: any) | dispatch(action: Object)`**
127127

128-
Dispatch an action. Returns the return value of the triggered action handler, or a Promise if multiple handlers are triggered. [Details](actions.md)
128+
分发一个 action。返回 action 方法的返回值,如果多个处理器被触发,那么返回一个 Pormise。[详细介绍](actions.md)
129129

130130
- **`replaceState(state: Object)`**
131131

132-
Replace the store's root state. Use this only for state hydration / time-travel purposes.
132+
替换 store 的根状态,仅用于调试 state
133133

134134
- **`watch(getter: Function, cb: Function, options?: Object)`**
135135

136-
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 接收 storestate 作为唯一参数。接收类似 vm.$watch 方法的参数的可选对象。
137137

138-
To stop watching, call the returned handle function.
138+
要停止检测,调用该方法的返回值 (watch 的返回值是个方法)。
139139

140140
- **`subscribe(handler: Function)`**
141141

142-
Subscribe to store mutations. The `handler` is called after every mutaiton and receives the mutation descriptor and post-mutation state as arguments:
142+
订阅(注册监听) store 的 mutation。handler 会再每个 mutation 完成后调用,接收 mutation 的描述对象和 经过 mutation 后的状态作为参数:
143143

144144
``` js
145145
store.subscribe((mutation, state) => {
@@ -148,34 +148,34 @@ const store = new Vuex.Store({ ...options })
148148
})
149149
```
150150

151-
Most commonly used in plugins. [Details](plugins.md)
151+
这是插件中常见的用法。 [详细介绍](plugins.md)
152152

153153
- **`registerModule(path: string | Array<string>, module: Module)`**
154154

155-
Register a dynamic module. [Details](modules.md#dynamic-module-registration)
155+
注册一个动态模块。 [详细介绍](modules.md#dynamic-module-registration)
156156

157157
- **`unregisterModule(path: string | Array<string>)`**
158158

159-
Unregister a dynamic module. [Details](modules.md#dynamic-module-registration)
159+
注销一个动态模块。 [详细介绍](modules.md#dynamic-module-registration)
160160

161161
- **`hotUpdate(newOptions: Object)`**
162162

163-
Hot swap new actions and mutations. [Details](hot-reload.md)
163+
热加载新的 action 和 mutation。 [详细介绍](hot-reload.md)
164164

165-
### Component Binding Helpers
165+
### 组件绑定助手
166166

167167
- **`mapState(map: Array<string> | Object): Object`**
168168

169-
Create component computed options that return the sub tree of the Vuex store. [Defails](state.md#the-mapstate-helper)
169+
创建一个组件的计算属性选项,该选项会返回 Vuex store 的子树 Create component computed options that return the sub tree of the Vuex store. [详细介绍](state.md#the-mapstate-helper)
170170

171171
- **`mapGetters(map: Array<string> | Object): Object`**
172172

173-
Create component computed options that return the evaluated value of a getter. [Details](getters.md#the-mapgetters-helper)
173+
创建一个组件的计算属性选项,该选项会返回 getter的计算后的值。 [详细介绍](getters.md#the-mapgetters-helper)
174174

175175
- **`mapActions(map: Array<string> | Object): Object`**
176176

177-
Create component methods options that dispatch an action. [Details](actions.md#dispatching-actions-in-components)
177+
创建一个组件的methods选项,该选项返回一个 action。 [详细介绍](actions.md#dispatching-actions-in-components)
178178

179179
- **`mapMutations(map: Array<string> | Object): Object`**
180180

181-
Create component methods options that commit a mutation. [Details](mutations.md#commiting-mutations-in-components)
181+
创建一个组件的methods选项,该选项提交一个 mutation。 [详细介绍](mutations.md#commiting-mutations-in-components)

0 commit comments

Comments
 (0)