ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.34k stars 8.14k forks source link

🧐[问题 | question]如何添加token #11179

Closed mayongkang1 closed 6 months ago

mayongkang1 commented 6 months ago

由于这个代码会在全局加载一次,这时还没有登录,所以console.log('执行了', token);,的token为null 导致后续的请求添加token时获取到的都是空,如何在登录之后手动再加载一次配置,求解

import type { RequestOptions } from '@@/plugin-request/request'; import {message} from "antd";

const token = JSON.parse(localStorage.getItem('token')) console.log('执行了', token); /**

github-actions[bot] commented 6 months ago

当前 Issue 未检测到标题,请规范填写,谢谢!

The title of the current issue is not detected, please fill in according to the specifications, thank you!

miaozilong commented 4 months ago

判断一下,如果localStorage里面没有token,就跳转到/user/login