On the data update of vue and vuex projects

create a project by yourself. When the page is loaded, you will get the login information through the API, and then save it in vuex. The code is as follows:

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);
  }
});

then I need to use this data on another page. Take the vue code as follows:
get.vue page


    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;
        ...
    }

everything is normal when jumping to through the route, but when I refresh the get.vue page, I can"t get this data. I tried to write it with computational attributes, which is easy to use, but there will be another problem. This page is submitted to the next step, and then click the previous step back. Because you need to execute an API in created to assign values to the computational attributes, you will report an error and study it for a long time. Hope to have similar experience under the guidance of God

Dec.14,2021
The

page is refreshed and the store is reset. You can judge in action that the user information in store is empty and request user information again.


userinfo in state is taken from localStorage or cookie, and commit is also stored in localStorage or cookie, so that even if the refresh message exists

Menu