【问题标题】:vue router can't delete queryVue路由器无法删除查询
【发布时间】:2021-03-12 11:34:15
【问题描述】:

我尝试通过单击按钮删除查询参数。

例如我的路线是http://localhost:8080/#/myroute?dialog=1。 现在我单击一个应该删除查询部分?dialog=1的按钮。

我的点击功能是这样的:

delete_query() {
  this.$router.replace({ query: null });
}

我也尝试过这种尝试:

delete_query() {
  this.$router.push({ query: null });
}

delete_query() {
  this.$router.push({ name: this.$route.name });
}

但是所有这些函数都给我同样的错误:

Uncaught (in promise) Error: Redirected when going from "/myroute?dialog=1" to "/myroute" via a navigation guard.

为什么? 我做错了什么?我该如何解决这个问题?

我已经安装了 vue router 的实际版本 3.5.1。

【问题讨论】:

    标签: vue.js vuejs2 vue-router


    【解决方案1】:

    如果我做对了,要删除 javascript 对象属性,您可以使用 javascript 的 delete 属性。像这样。

        delete_query() {
     delete this.$router.query // will delete all router queries 
     delete this.$router.query.name // will delete only name property.
    }

    【讨论】:

    • 是的,在一个应该可以工作但不适用于 vue 路由器的普通对象中。我没有收到错误,但查询参数没有从 url 中删除。
    猜你喜欢
    • 2020-12-11
    • 2021-10-19
    • 1970-01-01
    • 2017-06-22
    • 2019-08-15
    • 2016-01-02
    • 2018-04-13
    • 2017-11-24
    • 2018-04-14
    相关资源
    最近更新 更多