在main.js中:
// router文件夹下等index.js文件中写入
//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
return originalReplace.call(this, location).catch(err => err)
}
跳转使用:
this.$router
.push({ path: "/businessDetail", query: { id: it3.id } })
.catch((err) => {
console.log(err);
});
跳转页面监听:
watch: {
$route(to) {
this.updateQueryParams(to.query);
},
},
updateQueryParams(params) {
if (JSON.stringify(this.queryParams) !== JSON.stringify(params)) {
console.log("参数已经发生了变化", params);
// 进行相应处理...
// 更新queryParams对象
this.qid = params.id;
this.getdetail();
} else {
console.log("参数没有发生变化");
}
},
vue路由跳转同一页面,id改变,解决报错,参数改变重新请求页面内容
最新推荐文章于 2024-05-16 15:17:37 发布