异步使用路由this.$router.go(-1) 导致页面参数

2023-05-17  本文已影响0人  多记录多学习

问题:当你动态修改了A页面的query参数,然后更新A页面路由,然后跳转到B页面,B页面异步操作this.$router.go(-1),此时在A页面获取不到query参数;
解决:A页面需要延迟获取query参数,使用setTimeout(()=>{}, 0),即可正常获取query参数;
如图所示:


image.png
mounted() {
    this.getApi();
    this.createPermission();
    setTimeout(() => {
      const { moduleType } = this.$route.query;
      this.moduleType = moduleType || "touchedInstructions";
      console.log(window.location.href);
    }, 0);
    console.log(window.location.href);
  },
image.png
上一篇 下一篇

猜你喜欢

热点阅读