1、放入router文件下的index.js中
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err);
};
本文介绍了一种解决Vue Router在导航过程中出现未捕获错误的方法。通过覆盖VueRouter的push方法,确保了错误能够被正确捕获和处理,避免了页面加载时因错误而导致的用户体验下降。
1、放入router文件下的index.js中
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err);
};

被折叠的 条评论
为什么被折叠?