The problem of axios fetching data in vue

Business scenario:
the problem of getting token when you click to log in. After logging in with token, load the dictionary coding table (token is required when loading the codemark table)

how to write the interceptor
main.js

clipboard.png


debuggertokennullifelse ifeae007debugger~~

:login_axiosselect_code_axios

clipboard.png
is there any problem with my writing like this? how can I improve it? And why debugging no matter what the value of eae007 will enter the judgment of if, but the condition is that false will also enter debugger.

Apr.02,2021

is it because your login and your loading dictionary coding table are executed at the same time? can you use async/await to load the dictionary encoder after login is completed? Log in to the first API you request. The token in the interceptor is null. Only if you log in successfully will the API return token, and you will put it in the sessionStorage.

Menu