const store=new Vuex.Store({
state:{
nickName:'',
cartCount:0,
},
mutations:{
updateUserInfo(state,nickName){
state.nickName=nickName;
}
},
actions:{
updateUserInfoAction(context,nickName){
context.commit('updataUserInfo',nickName)
}
}
})
//前台页面部分
computed:{
nickName(){
return this.$store.state.nickName
}
},
axios.get('/users/checkLogin').then( (response)=>{
let res=response.data;
if(res.status=='0'){
this.$store.dispatch('updateUserInfoAction',res.result.userName)
}
} )
TCircley
相关分类