自己弄个项目,在页面加载的时候会通过接口获取登录人的信息,然后存到vuex中,代码如下:
util.request.post({
url: "combination/pagehead",
that: this,
success: result => {
console.log(result);
this.userinfo = result.data.data.memberinfo;
this.$store.commit("saveUserInfo", this.userinfo);
this.apprcount = result.data.data.approvalcount.count;
this.receiptcount = result.data.data.receiptcount.count;
this.list = result.data.data.menulist
},
fail: error => {
console.log(error);
}
});
然后在另一个页面我需要用到这个数据,取vue代码如下
get.vue页面
created() {
...
this.department.dept_name = this.$store.state.userinfo.dept_name;
this.department.dep_deptno = this.$store.state.userinfo.dept_no;
this.department.com_companyno = this.$store.state.userinfo.corp_code;
this.department.com_companyname = this.$store.state.userinfo.corp_name;
this.department.area_group = this.$store.state.userinfo.area_group;
this.department.bg_code = this.$store.state.userinfo.bg_code;
this.entryPerson = this.$store.state.userinfo.display_name;
this.entryPersonNo = this.$store.state.userinfo.user_code;
...
}
在正常通过路由跳转到的时候,是一切正常的,但是当我在get.vue页面刷新的时候就娶不到这个数据了,尝试了一下用计算属性去写,是好用的,但是会出现另一个问题的,这个页面提交到下一步后再点上一步回来,因为需要在created中执行一个接口给计算属性赋值,所以会报错,研究好长时间了,希望有过类似经验的大神指点下
页面刷新,store重置了,可以在action中判断下,store中用户信息为空后再次请求用户信息。