oj判题系统-vue中async和await是否失效问题

在oj判题系统的第一期,全局权限管理优化中



我的代码:

import router from "@/router";
import store from "@/store";
import ACCESS_ENUM from "@/access/accessEnum";
import checkAccess from "@/access/checkAccess";
/**
* to, 要跳转到的页面
* from, 要进行跳转的页面
* next 函数,显示调用 next() 即表示放行,跳转到路由已规定的路由页面
*/

router.beforeEach(async (to, from, next) => {
const loginUser = store.state.user.loginUser;
console.log("用户登录状态", loginUser);
// 如果之前没登录过,自动登录
if (!loginUser || !loginUser.userRole) {
// 加 await 是为了等用户登录成功之后,再执行后续的代码
await store.dispatch("user/getLoginUser");
}
const needAccess = (to.meta?.access as string) ?? ACCESS_ENUM.NO_LOGIN;
if (needAccess !== ACCESS_ENUM.NO_LOGIN) {
console.log("后续操作", loginUser);
if (!loginUser || !loginUser.userRole) {
next(`/user/login?redirect=${to.fullPath}`);
return;
}
if (!checkAccess(loginUser, needAccess)) {
next("/noAuth");
return;
}
}
next();
});


我的代码运行结果如下

所以,我就觉得异步方法await没生效,但我也对比了鱼皮的源代码,所以来求助大伙!

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
长_34322
作者分享
有没有做完 rpc项目 第二章 全局加载配置 扩展 的鱼友,教教我怎么实现监听配置文件的变更和自动更新呗😀 这是我的代码: public class ConfigFileWatcher { private Props props; public ConfigFileWatcher(String configFileName) throws IOException, URISyntaxException { //加载配置文件 this.props = new Props(configFileName); //启动配置文件监听 startConfigFileWatcher(props, configFileName); } private static void startConfigFileWatcher(Props props, String filePath) throws URISyntaxException { //todo 获取资源文件的URL 要适配linux URL resourceUrl = ConfigFileWatcher.class.getResource("/"+filePath); if (resourceUrl == null) { return; } // 将URL转换为Path Path path = null; try { path = Paths.get(resourceUrl.toURI()).getParent(); } catch (URISyntaxException e) { throw new RuntimeException(e); } if (path == null) { System.err.println("无法获取资源文件的父目录: " + resourceUrl); return; } // 输出父目录 System.out.println("资源文件的父目录: " + path); // 创建一个简单的监听器 Watcher watcher = new SimpleWatcher() { @Override public void onModify(WatchEvent<?> event, Path currentPath) { if (currentPath.endsWith(filePath)) { Console.log("配置文件已修改,重新加载..."); // 重新加载配置文件 props.autoLoad(true); } } }; try{ // 创建并启动监控器 WatchMonitor watchMonitor = WatchMonitor.create(path); watchMonitor.setWatcher(watcher); watchMonitor.start(); }catch (Exception e) { Console.error(e, "无法启动配置文件监听器: {}", path); } } } 在ConfigUtils里 //加载文件 ConfigFileWatcher watcher = new ConfigFileWatcher(application.toString()); return watcher.getProps().toBean(clazz,Prefix); 应该是我理解不够,还是没做出来😜,求各路大佬指点和分享
3
我已通关码神挑战,一起来玩呀~https://1024.codefather.cn/ 6
1
求,生产者能动态的获取序列化器选择配置
3
有鱼友了解对日开发吗,找的java实习岗!在沈阳东软,实习工资2000包住宿,今天得到邮件实习通知,目前就这一个实习,还在犹豫!
12
补作业:伙伴匹配系统,解决某个sql语句错误的方法
9
下载 APP