From e66cc30c3a19f5b1bbd6f9b0e848c005e6972b2b Mon Sep 17 00:00:00 2001 From: Eido Askayo Date: Sun, 3 Mar 2019 11:35:10 +0200 Subject: [PATCH] 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: https://github.com/vuejs/vuex/issues/1118 --- src/auth/store.js | 8 ++++++-- src/store/common.js | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/auth/store.js b/src/auth/store.js index 64cf2c8..15358b9 100644 --- a/src/auth/store.js +++ b/src/auth/store.js @@ -15,10 +15,14 @@ const auth = { mutations: { update (state, data) { - state = Object.assign({}, defaults, data) + Object.keys(state).forEach(index => { + state[index] = data[index] + }) }, clear (state) { - state = Object.assign(state, defaults) + Object.keys(state).forEach(index => { + state[index] = defaults[index] + }) } }, diff --git a/src/store/common.js b/src/store/common.js index ac6e524..756a928 100644 --- a/src/store/common.js +++ b/src/store/common.js @@ -54,7 +54,9 @@ export default { }, clear (state) { - state = Object.assign({}, defaults) + Object.keys(state).forEach(index => { + state[index] = defaults[index] + }) } },