12345678910111213141516171819202122232425262728293031323334353637383940 |
- import axios from "axios";
- //axios 配置
- const instance = axios.create({
- headers: {
- "Content-Type": "application/json"
- },
- timeout: 3000000,
- retry: 4, //重新请求次数
- retryDelay: 1000, //重新请求的间隔
- })
- instance.interceptors.request.use(config => {
- // 在发送请求之前做些什么,比如传token
- const token = localStorage.getItem('token');
- const projectId = localStorage.getItem('projectId');
- if (token) {
- config.headers.Authorization = token;
- }
- if (projectId) {
- config.headers.ProjectId = projectId;
- }
- return config
- }, error => {
- console.log(error)
- return Promise.reject(error)
- })
- // 添加相应拦截器
- instance.interceptors.response.use(response => {
- //对相应的数据做处理
- const res = response;
- return res;
- }, error => {
- console.error(error)
- return Promise.reject(error)
- })
- export default instance
|