我是在main.js中 使用了interceptors 拦截器 ,在每次请求时,检查localStorage中的jtwtoken 有就给请求设置头部然后执行请求,没有直接进行请求 axios.interceptors.request.use(function (req) { const AUTH_TOKEN = window.localStorage.getItem('jwttoken') if (AUTH_TOKEN) { req.headers['jwttoken'] = AUTH_TOKEN } // console.log(req.headers) return req }, function (error) { console.log('here') // 对请求错误做些什么 返回失败 return Promise.reject(error) })
我是在main.js中 使用了interceptors 拦截器 ,在每次请求时,检查localStorage中的jtwtoken 有就给请求设置头部然后执行请求,没有直接进行请求