vue使用vuex时刷新页面数据丢失

 

 

 

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
  name: window.sessionStorage.getItem('nameObj') ? JSON.parse(window.sessionStorage.getItem('nameObj')) : ''
}
const mutations = {
  cahgeWithParam (state, obj) {
    console.log(obj);
    state.name = obj.name
    console.log('这里', state.name);
    window.sessionStorage.setItem('nameObj', JSON.stringify(obj.name))
  }
}
export default new Vuex.Store({
  state,
  mutations
})

 

posted @ 2022-01-05 17:44  light丶  阅读(54)  评论(0)    收藏  举报