Vue?Router修改query參數(shù)url參數(shù)沒有變化問題及解決
Router修改query參數(shù)url參數(shù)沒有變化問題
正常情況下
this.$router.push({
query:{}
})
this.$router.replace({
query:{}
})就可以修改了
但是當已有query對象里面修改其中一個值,就會發(fā)現(xiàn)雖然this.$route.query發(fā)生改變但是瀏覽器的url上的參數(shù)并沒有發(fā)生變化, 嘗試將已有的參數(shù)進行深拷貝突然發(fā)現(xiàn)就可以了
let newQuery= JSON.parse(JSON.stringify(this.$route.query));
newQuery.index = 2;
this.$router.replace({
query: newQuery
})vueRouter不切換url只修改query報錯
使用push的話 會導致返回歷史有記錄
this.$router.push({
? query: {
? ? id: this.processId
? }
})所以需要使用
this.$router.replace({
? query: {
? ? id: this.processId
? }
})雖然不影響使用,但是會報如下錯誤
![]()
解決方案
在router.js加上這段
import VueRouter from 'vue-router'
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (location) {
return originalReplace.call(this, location).catch(err => err)
}
// push的同理
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
return originalPush.call(this, location).catch(err => err)
}注 適用于3.0.0版本的vue-router, 3.4.x可能會報錯.catch獲取不到
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Vue 關閉當前頁、關閉當前標簽tagsView的實現(xiàn)方法
這篇文章主要介紹了Vue 關閉當前頁、關閉當前標簽tagsView,主要有兩種方式,一種是在vue頁面直接實現(xiàn),另一種在js文件中寫自定義函數(shù),在vue頁面中調(diào)用,本文通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-08-08
vue環(huán)境如何實現(xiàn)div?focus?blur焦點事件
這篇文章主要介紹了vue環(huán)境如何實現(xiàn)div?focus?blur焦點事件,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
Vue將將后端返回的list數(shù)據(jù)轉化為樹結構的實現(xiàn)
本文主要介紹了Vue將將后端返回的list數(shù)據(jù)轉化為樹結構的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-05-05
Vue如何根據(jù)id在數(shù)組中取出數(shù)據(jù)
這篇文章主要介紹了Vue如何根據(jù)id在數(shù)組中取出數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08

