Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7ebf4a6

Browse files
authoredOct 10, 2018
Warn about vuex module reuse
Vuex modules must be constructed in a special way to avoid the stateful singleton problem. Warn about it.
1 parent ca042b4 commit 7ebf4a6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 

‎docs/guide/structure.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,25 @@ export default context => {
121121
return app
122122
}
123123
```
124+
125+
## Vuex module reuse
126+
127+
[Multiple vuex module instances](https://vuex.vuejs.org/guide/modules.html#module-reuse) can share references to the same underlying state objects. The state at each render will be polluted with references to the state at previous renders. We can prevent this undesired behaviour. Instead of assigning a simple object to the `state` module property, we must assign a function that returns a new state object each time that it is invoked.
128+
129+
``` js
130+
const module = {
131+
state () {
132+
return {
133+
foo: 'bar'
134+
}
135+
},
136+
mutations: {
137+
incrementFoo (state) {
138+
...
139+
},
140+
}
141+
// actions, getters...
142+
}
143+
```
144+
145+
vuex module reuse

0 commit comments

Comments
 (0)
Please sign in to comment.