Skip to content

Commit e66cc30

Browse files
committed
Fix store state replacement
When replacing the store state with simple variable assignment, the state object looses its observer and won't be reactive anymore. Instead of replacing the whole state, each of the state's properties should be replaced. Source: vuejs/vuex#1118
1 parent 6d2259e commit e66cc30

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/auth/store.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ const auth = {
1515

1616
mutations: {
1717
update (state, data) {
18-
state = Object.assign({}, defaults, data)
18+
Object.keys(state).forEach(index => {
19+
state[index] = data[index]
20+
})
1921
},
2022
clear (state) {
21-
state = Object.assign(state, defaults)
23+
Object.keys(state).forEach(index => {
24+
state[index] = defaults[index]
25+
})
2226
}
2327
},
2428

src/store/common.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export default {
5454
},
5555

5656
clear (state) {
57-
state = Object.assign({}, defaults)
57+
Object.keys(state).forEach(index => {
58+
state[index] = defaults[index]
59+
})
5860
}
5961
},
6062

0 commit comments

Comments
 (0)