vue重写路由push方法
/**
- 重写路由的push方法
- 解决,相同路由跳转时,报错
- 添加,相同路由跳转时,触发watch (仅限string方式传参,形如"view?id=5")
*/
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
if(typeof(location)=="string"){
var Separator = "&";
if(location.indexOf('?')==-1) { Separator='?'; }
location = location + Separator + "random=" + Math.random();
}
return routerPush.call(this, location).catch(error=> error)
}
本文介绍了一种在Vue项目中重写路由push方法的技巧,解决了相同路由重复跳转时的错误,并在字符串传参时触发watch,确保了应用的稳定性和用户体验。
1285

被折叠的 条评论
为什么被折叠?



