Vuex 刷新失效问题

Vuex的生命周期是页面缓存,刷新就失效了
解决办法借助缓存

import Cookies from 'js-cookie'
const state = {
  userInfo: null || Cookies.get('userInfo')
}

const mutations = {
  SET_USERINFO: (state, userInfo) => {
    state.userInfo = userInfo
    var date = new Date(new Date().getTime() + 120 * 60 * 1000)
    Cookies.set('userInfo', userInfo, { expires: date })
  }
}

const actions = {
  toggleUserInfo({ commit }, userInfo) {
    commit('SET_USERINFO', userInfo)
  }
}
posted @ 2020-10-24 00:48  Blog老中医  阅读(872)  评论(1编辑  收藏  举报