原来的状态(页面刷新数据会重置)
代码语言:javascript复制state: {
teamA: '主队'
},
mutations: {
data_teamA(state, x) {
state.teamA = x
}
},
解决后(页面刷新保留store数据)
代码语言:javascript复制state: {
teamA: JSON.parse(sessionStorage.getItem("teamA")) || '主队'
},
mutations: {
data_teamA(state, x) {
sessionStorage.setItem('teamA', JSON.stringify(x))
state.teamA = x
}
},