解决编程式导航重复点击报错问题
给router文件中添加下列代码//解决重复点击导航问题Vue.use(VueRouter); // 使用一个vue插件constVueRouterPush=VueRouter.prototype.push;VueRouter.prototype.push=functionpush(to){returnVueRouterPush.call(this,to).catch(err=>err)}.
·
描述: 编程式路由跳转到当前路由(参数不变), 会抛出NavigationDuplicated的警告错误
声明式路由跳转内部已经处理原因:vue-router3.1.0之后, 引入了push()的promise的语法
如果没有通过参数指定成功或者失败回调函数就返回一个promise来指定成功/失败的回调
且内部会判断如果要跳转的路径和参数都没有变化, 会抛出一个失败的promise解决: 1:在跳转时指定成功或失败的回调函数, 或者catch处理错误
2: 修正Vue原型上的push和replace方法 (优秀)
原文地址https://www.cnblogs.com/fsg6/p/13320969.html?utm_source=tuicool
给router文件中添加下列代码
//解决重复点击导航问题
Vue.use(VueRouter); // 使用一个vue插件
const VueRouterPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push (to) {
return VueRouterPush.call(this, to).catch(err => err)
}
更多推荐
已为社区贡献1条内容
所有评论(0)