vue.js - 如何为我的 Vue 应用程序修复“未处理的承诺拒绝”?
问题描述
对于我的 Vue 应用程序,我在 IE 中遇到以下问题:'Unhandled Promise Rejection undefined'。
我将问题追溯到应用程序的身份验证。但我不确定如何解决它。我在 next() 函数周围尝试了 try-catch 块。
下面是验证码。
import router from '@/config/Router';
import CONST from '@/utils/Constants';
import ObjectHelper from "@/helpers/ObjectHelper";
class Auth {
constructor() {
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
if (!Auth.isLoggedIn()) {
next({path: CONST.ROUTE.SESSION.LOGIN});
} else {
next();
}
} else {
next();
}
});
}
static logOut() {
localStorage.clear();
sessionStorage.clear();
router.replace(CONST.ROUTE.SESSION.LOGIN);
}
static isLoggedIn() {
return ObjectHelper.exists(localStorage.getItem(CONST.KEY.AUTH.ACCESS_TOKEN));
}
}
export default Auth;
在this.$router.push(CONST.ROUTE.ORGANISATIONS.OVERVIEW);
我的登录组件中,错误被抛出。
为了完整起见,我还提供了路由器的代码:
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
export default new Router({
base: process.env.BASE_URL,
mode: 'history',
routes: [
{
path: '/',
name: 'home',
component: () => import('@/views/home/home.vue')
},{
path: '/session',
name: 'session',
component: () => import('@/views/session/session.vue'),
children: [
{
path: 'login',
name: 'login',
component: () => import('@/views/session/login/login.vue')
},
{
path: 'logout',
name: 'logout',
component: () => import('@/views/session/logout/logout.vue')
}
]
},
{
path: '/organisations',
alias: '/organisaties',
component: () => import('@/views/organisations/organisations.vue'),
children: [
{
path: '',
name: 'organisations-overview',
component: () => import('@/views/organisations/overview/overview.vue'),
meta: {
requiresAuth: true,
can: 'edit-organisations',
fail: '/session/logout'
}
},
{
path: ':uuid',
name: 'organisation-edit',
component: () => import('@/views/organisations/edit/edit.vue'),
meta: {
requiresAuth: true,
can: 'edit-organisations',
fail: '/session/logout'
}
}
]
}
]
});
有人知道如何解决这个问题吗?非常感谢!
解决方案
我在 IE 中找到了“未处理的承诺拒绝未定义”的解决方案。我需要在我的 Vue 项目中添加对 IE11 的支持:'babel-polyfill'、'weakmap-polyfill'、'core-js/es/set'、'core-js/es/map'。在此之后,一切正常。
推荐阅读
- c - 使用函数冒泡排序动态数组
- javascript - vue.js - 如何查看嵌套对象的属性并获取索引?
- macos - imageMagick : 将图像的颜色替换为 tintColor
- java - 使用 testNG 和 gradle 进行 Spring Boot 测试
- web - 如何允许在 EC2 中使用 Linux AMI 进行 Web 托管(添加了端口 80 规则)
- security - Micronaut 会话登录代码在启动时失败
- python - 找到一年中排名前 n 的客户,然后在一年中的每个月存储这些客户的交易量
- json - 在 PostgreSQL 中,如何生成没有反斜杠和外部双引号的干净 JSON?
- python - Scikit-learn 数据索引和引用
- android - AudioTrack:AudioFlinger 无法创建轨道,状态:-32