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/actions.md
+66-1Lines changed: 66 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ const vm = new Vue({
67
67
})
68
68
```
69
69
70
-
What the above code does is bind the raw `incrementBy` action to the component's store instance, and expose it on the component as an instance method, `vm.incrementBy`. Any arguments passed to `vm.incrementBy` will be passed to the raw action function after the first argument which is the store, so calling:
70
+
What the above code does is to bind the raw `incrementBy` action to the component's store instance, and expose it on the component as an instance method, `vm.incrementBy`. Any arguments passed to `vm.incrementBy` will be passed to the raw action function after the first argument which is the store, so calling:
71
71
72
72
```js
73
73
vm.incrementBy(1)
@@ -132,3 +132,68 @@ const vm = new Vue({
132
132
}
133
133
})
134
134
```
135
+
136
+
### Arrange Actions in Modules
137
+
138
+
Normally in large applications, actions should be arranged in groups/modules for different purposes. For example, userActions module deals with user registration, login, logout, and so on, while shoppingCartActions module deals with other tasks for shopping.
139
+
140
+
Modularization is more convenient for different components to import only required actions.
141
+
142
+
You may import action module into action module for reusability.
While calling actions from one another module, or while calling another action in the same module, remember that actions take a store instance as its first argument, so the action called inside another action should be passed through the first argument for the caller.
178
+
179
+
If you write the action with ES6 destructuring style, make sure that the first argument of the caller action covers all the properties and methods of both actions. For example, only *dispatch* is used in the caller action and *state*, *watch* are used in the called action, all the *dispatch*, *state* and *watch* should be presented in the caller first formal argument like this:
180
+
181
+
```javascript
182
+
import {callee} from'./anotherActionModule'
183
+
184
+
exportconstcaller= ({dispatch, state, watch}) {
185
+
dispatch('MUTATION_1')
186
+
callee({state, watch})
187
+
}
188
+
```
189
+
190
+
Otherwise, you should use the old-fationed function syntax:
0 commit comments