javascript - beforeEach 中的承诺(Nuxt/vue-router)
问题描述
我试图在路由更改之前发送 POST 请求以验证用户凭据,我最终在 Nuxt 插件中实现了该逻辑。但 Nuxt 不会等待承诺得到解决。我怎样才能做到这一点?我试过使用 async/await 但结果是一样的。
export default async ({ app }, inject) => {
app.router.beforeEach(function(to, from, next) {
if (app.$cookies.get('JWT')) {
app.$axios.$post('http://localhost:3000/verify', '2').then((res) => {
console.log('We are here! This is expected to continue...')
next()
})
} else {
console.log('No cookie!')
next(false)
}
})
}
*编辑:添加屏幕截图
解决方案
推荐阅读
- oracle - 在 powershell 中使用作业执行 sqlplus 会话
- django - django模板不输出多个表单并保存到modelform
- amazon-web-services - AWS 签名创建。对如何将 SigningKey 和 SingingString 转换为 Signature 感到困惑。AWS 示例似乎没有产生预期的结果
- php - foreach 在 foreach laravel
- android - 抽屉布局不起作用android
- android - 应该在自定义列表视图中同时使用列表视图 setOnItemClickListener 和可编辑的编辑文本
- neo4j - Neo4j 中的关系(边缘)没有被创建
- jquery - 使用 jquery 在选择选项中添加默认值
- image - 如何在图像 url 参数中发送 Post 请求(在 Get 请求中)
- javascript - 在角度 4 中悬停时在特定表格单元格上显示项目