store.js:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
export const store = new Vuex.Store({
state:{
userId:''
},
getters:{
isLogin(state){
if (!state.userId) { //防止刷新页面获取不到
state.userId=sessionStorage.getItem('userId');
}
return state.userId
}
},
mutations:{
removeUserId(state,payload){ //更新 state 方法
sessionStorage.removeItem("userId");
state.userId = ''
}
}
})
调用
computed:{
companyInfo(){
return this.$store.state.enterpriseInfo
return this.$store.getters.getWelfareTotalNumber //这个地方取得是getters 刷新页面中也会有
}
},
主动更新
this.$store.commit("authentEnterPrise",{companyData:companyObj});
网友评论