import axios from 'axios';
const service = axios.create({
baseURL: 'http://10.122.105.117:3000/mock/14', // url = base url + request url
timeout: 5000 // request timeout
});
axios请求拦截和加token
service.interceptors.request.use(
(config) => {
return config;
// do something before request is sent
// if (store.getters.token) {
// // let each request carry token
// // ['X-Token'] is a custom headers key
// // please modify it according to the actual situation
// config.headers['X-Token'] = getToken()
// }
},
(error) => { return Promise.reject(error) }
)
axios实例化
axios请求拦截和加token
和响应拦截
API封装