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: docs/en/api.md
+64-24
Original file line number
Diff line number
Diff line change
@@ -20,12 +20,40 @@ const store = new Vuex.Store({ ...options })
20
20
21
21
-**mutations**
22
22
23
-
- type: `Object`
23
+
- type: `{ [type: string]: Function }`
24
24
25
-
An object where each entry's key is the mutation name and the value is a mutation handler function. The handler function always receives `state` as the first argument, and receives all arguments passed to the dispatch call following that.
25
+
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.
26
26
27
27
[Details](mutations.md)
28
28
29
+
-**actions**
30
+
31
+
- type: `{ [type: string]: Function }`
32
+
33
+
Register actions on the store. The handler function receives a `context` object that exposes the following properties:
34
+
35
+
```js
36
+
{
37
+
state, // same as store.state, or local state if in modules
38
+
rootState, // same as store.state, only in modules
39
+
commit, // same as store.commit
40
+
dispatch, // same as store.dispatch
41
+
getters // same as store.getters
42
+
}
43
+
```
44
+
45
+
[Details](actions.md)
46
+
47
+
-**getters**
48
+
49
+
- type:`{ [key: string]: Function }`
50
+
51
+
Register getters on the store. The getter function receives the `state` as the first argument (willbemodulelocalstateifdefinedinamodule).
52
+
53
+
Registered getters are exposed on `store.getters`.
54
+
55
+
[Details](getters.md)
56
+
29
57
- **modules**
30
58
31
59
- type: `Object`
@@ -36,13 +64,18 @@ const store = new Vuex.Store({ ...options })
36
64
{
37
65
key: {
38
66
state,
39
-
mutations
67
+
mutations,
68
+
actions?,
69
+
getters?,
70
+
modules?
40
71
},
41
72
...
42
73
}
43
74
```
44
75
45
-
Each module can contain `state` and `mutations` similar to the root options. Amodule's state will be attached to the store's root state using the module's key. A module's mutations will only receives the module's own state as the first argument instead of the root state.
76
+
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.
77
+
78
+
[Details](modules.md)
46
79
47
80
- **plugins**
48
81
@@ -69,40 +102,33 @@ const store = new Vuex.Store({ ...options })
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.
98
128
99
129
To stop watching, call the returned handle function.
100
130
101
-
- **hotUpdate(newOptions:Object)**
102
-
103
-
Hot swap new actions and mutations. [Details](hot-reload.md)
104
-
105
-
- **subscribe(handler: Function)**
131
+
- **`subscribe(handler:Function)`**
106
132
107
133
Subscribe to store mutations. The `handler` is called after every mutaiton and receives the mutation descriptor and post-mutation state as arguments:
108
134
@@ -112,3 +138,17 @@ const store = new Vuex.Store({ ...options })
112
138
console.log(mutation.payload)
113
139
})
114
140
```
141
+
142
+
Most commonly used in plugins. [Details](plugins.md)
0 commit comments