17370845950

vue-router清除url地址栏路由参数的操作代码

this.reportId = this.$route.query.reportCoreId;

在另一个页面得到这个id之后,刷新浏览器页面还是会存在在url地址栏中

然后再这样就可以清除地址栏路由参数

  mounted() {
    // 获取当前路由的查询参数
    const query = { ...this.$route.query };
    // 删除指定的查询参数
    delete query.reportCoreId;
    // 使用 $router.replace() 方法更新路由
    this.$router.replace({ query });
  },