vue项目重复点击一个路由会报错如何解决

在新版本的vue-router中,重复点击同一个路由会出现以下报错 :

 这个问题时vue-router 3.2.0版本的一个小Bug

方法有很多,比如降低路由版本(不推荐),但是推荐下面这种方式,比较简单靠谱

// 把这段代码直接粘贴到router/index.js中的Vue.use(VueRouter)之前
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function(location) {
  return originalPush.call(this, location).catch(err => {})
};

猜你喜欢

转载自blog.csdn.net/shi15926lei/article/details/130536356