来自 AngularJS,我认为这在 Vue.js 2 中也很容易。但在 Vue 中这似乎很难设计。
在 AngularJS 中我可以这样做 $location.search('my_param', null);
这将有效地转换 https://mydomain.io/#/?my_param=872136
到 https://mydomain.io/#/
。
在 Vue 中,我尝试了 this.$router.replace('my_param',null);
,但它只会执行 https://mydomain.io/#/?my_param =872136
-> https://mydomain.io/#/my_param
,留下空的my_param。
Vuejs2 中没有从 Url 中删除查询参数的方法吗?我应该使用纯 JS 来实现吗?
最佳答案
router.replace()
是通过从浏览器历史堆栈中删除当前 URL 并将其替换为您传递给它的参数路由来进行导航。
实际语法是router.replace(url_location, onComplete, onAbort)
。
您正在做的是 router.replace(my_param, null)
,它从历史堆栈中删除当前 URL 并将其替换为 'my_param'
并且对于onComplete
回调你正在传递一个 null
所以这样做:
this.$router.replace('/')
有关 programatic navigation 的更多信息
关于javascript - 从 Url 中删除查询字符串参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45234567/