Holle! 我是Boy~,今天给大家分享一下关于 Vue 解决路由重复 Uncaught (in promise)错误 的问题。 话不多说直接来看
在脚手架router文件夹的index.js写入:
1、第一种方法
const routerPush = VueRouter.prototype.push
VueRouter.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)
}
2、第二种方法
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
return VueRouterPush.call(this, to).catch(err => err)
}
如果对你有帮助 不妨点个赞关注一下(强老板大气),后续我也会发布一些对你有帮助的文章 !!!