971be918 by renchao@pashanhoo.com

style:cas配置

1 parent c78c3b0e
1 /* 1 /*
2 * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 2 * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
3 * @Autor: renchao 3 * @Autor: renchao
4 * @LastEditTime: 2023-06-01 16:05:00 4 * @LastEditTime: 2023-06-02 10:07:55
5 */ 5 */
6 import axios from 'axios' 6 import axios from 'axios'
7 import Cookies from 'js-cookie' 7 import Cookies from 'js-cookie'
...@@ -32,6 +32,14 @@ service.interceptors.request.use( ...@@ -32,6 +32,14 @@ service.interceptors.request.use(
32 } else { 32 } else {
33 config.headers.delete('Authorization') 33 config.headers.delete('Authorization')
34 } 34 }
35 } else {
36 const token = Cookies.get('token')
37 // 添加请求头
38 if (token) {
39 config.headers['Authorization'] = 'Bearer ' + token
40 } else {
41 config.headers.delete('Authorization')
42 }
35 } 43 }
36 return config 44 return config
37 }, 45 },
......