vue.js - Vue路由器 - 克服下一个({})未捕获(承诺)未定义错误
问题描述
我随机收到关于使用next({ path: 'dfdfd' })
.
我认为该错误正在Uncaught (in promise) undefined
阻止我的脚本的其余部分运行。
我已经尝试了网络上的所有选项,但所有选项都涉及使用$router.push
not next()
。
next({path: '/profile'}, () => {});
next({path: '/profile'}).catch(()=> {});
try { next({path: '/profile'}) } catch(err){}
不要做任何事。
谁能告诉我如何发现这个错误?
问候
编辑。
以上用于从 vue-routersbeforeRouteEnter
和beforeRouteUpdate
方法调用的 axios 请求的错误处理。
/**
* Error Handler
* @param error
* @param next
* @param to
* @param from
*/
errorHandler(error, next, to, from) {
switch(error.response.status) {
case 401:
if(from.path !== '/login') {
next({path: '/login'});
} else {
next();
}
break;
case 498:
for(let i in error.response.data.errors) {
db.commit('setNotifications', []);
db.commit('addErrorNotification', error.response.data.errors[i][0]);
}
if(from.path !== '/profile') {
next({path: '/profile'}); // where the error is thrown
} else {
next();
}
break;
default:
next();
break;
}
db.commit('setPageLoading', false);
}
解决方案
推荐阅读
- c# - 如何在实时图表中删除工具提示百分比
- angular - 带有输入验证的 Angular Material DatePicker
- c++ - 通过迭代器插入到 STL 集中
- javascript - 使用 UWP 应用中的通知导航到特定页面
- python - 读取文件夹中的所有文本文件并更改字符串中的字符(如果出现)
- mysql - 修复错误 1241 操作数应包含 1 列
- ios - Plotly.js 在渲染大型数据集时会阻塞 UI。它有任何下采样功能吗?
- postgresql - PostgreSQL:在数字之前对字母进行排序
- c# - ASP.NET 4.6 和 Core 之间的路由差异
- html - 在 Safari 中禁用平铺背景平滑