报错原因:vue路由编程式导航,跳转页面且参数不变,多次执行后会抛出NavigationDuplicated 的警告错误,但不影响程序。
解决方案:
1.在跳转时加两个成功与失败的回调 ()=>{},()=>{}
this.$router.push({....},()=>{},()=>{})
2.重写push与replace方法
call函数的用法:http:// https://www.runoob.com/w3cnote/js-call-apply-bind.html
//把VueRouter原型对象的push与replace,报存一份
let originPush = VueRouter.prototype.push;
//参数一:(告诉原来push方法,你往哪里跳) 参数二,三:成功与失败
VueRouter.prototype.push = function(location,resolve,reject){
if(resolve && reject){
//调用上面报存的push方法【this:VueRouter 】
// call函数的用法:
//https://www.runoob.com/w3cnote/js-call-apply-bind.html
originPush.call(this,location,resolve,reject);
}else{
originPush.call(this,location,()=>{},()=>{});
}
}