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

问题:当你动态修改了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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容