原因:vue-router版本升级,返回promise对象,导致之前的this.$router.push()出错,但是不影响功能的实现
解决方案:
在src下router中的index.js中添加代码,重写push和replace方法
PS:一定要放在vueRouter实例创建之前
代码:
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)
}