Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.

Commit f62bcec

Browse files
authored
fix: correct presisted state logic under dev mode(#10)
2 parents d3479e0 + 690cd75 commit f62bcec

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default {
3131
3232
computed: {
3333
currentLayout () {
34+
// ! 必须将 formatLayoutKey 从字符串模板中抽离出来,否则 this.layout 变化时,
35+
// 将不会触发 computed 的计算
3436
const formatLayoutKey = this.layout
3537
.replace(/^[a-z]/, key => key.toUpperCase())
3638

src/store/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import actions from './actions'
1313
import modules from './modules'
1414

1515
const __DEV__ = process.env.NODE_ENV === 'development'
16+
// https://github.com/robinvdvleuten/vuex-persistedstate
17+
// https://github.com/js-cookie/js-cookie
1618
const persistedState = createPersistedState({
1719
key: '$_VUEX_STORE',
18-
storage: { // default: window.localStorage
20+
// default: window.localStorage
21+
storage: {
1922
getItem: key => Cookies.get(key),
20-
setItem: (key, value) => Cookies.set(key, value, { expires: 3, secure: true }),
21-
removeItem: key => Cookies.remove(key)
23+
// `expires: default`: Cookie is removed when the user closes the browser.
24+
setItem: (key, value) => Cookies.set(key, value, { secure: !__DEV__ }),
25+
removeItem: key => Cookies.remove(key, Cookies.get(key))
2226
}
2327
})
2428

@@ -31,7 +35,5 @@ export default new Vuex.Store({
3135
mutations,
3236
actions,
3337
strict: __DEV__,
34-
plugins: __DEV__
35-
? [createLogger(), persistedState]
36-
: [persistedState]
38+
plugins: __DEV__ ? [createLogger(), persistedState] : [persistedState]
3739
})

0 commit comments

Comments
 (0)