axios request intercepts the request header object and adds the Authorization field for token verification

Set it up in main.js

//aixos
import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
//axios请求拦截器
axios.interceptors.request.use(config =>{
    
    
  //为请求头对象添加token验证的 Authorization 字段 
  config.headers.Authorization = window.sessionStorage.getItem('token')
  console.log(config);
  return config
})

Insert image description here
Its function is the same as resending a complete request, but it actually adds something to the request header. a token
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_44239550/article/details/128679046