2022-02-28 19:09:39 +08:00
|
|
|
import axios from 'axios'
|
2020-05-01 21:30:25 +08:00
|
|
|
|
|
|
|
// 创建axios实例
|
|
|
|
const service = axios.create({
|
2022-02-28 19:09:39 +08:00
|
|
|
baseURL: ``,
|
2021-11-26 23:42:56 +08:00
|
|
|
timeout: 30 * 1000, // 请求超时时间
|
2022-02-28 19:09:39 +08:00
|
|
|
})
|
2020-05-01 21:30:25 +08:00
|
|
|
|
|
|
|
service.interceptors.request.use(
|
2021-02-28 14:50:52 +08:00
|
|
|
(config) => {
|
|
|
|
if (/^(post)|(put)|(delete)$/i.test(config.method)) {
|
|
|
|
if (config.data && config.data.upload) {
|
2022-02-28 19:09:39 +08:00
|
|
|
config.headers[`Content-Type`] = `multipart/form-data`
|
2021-02-28 14:50:52 +08:00
|
|
|
}
|
2020-05-01 21:30:25 +08:00
|
|
|
}
|
2022-02-28 19:09:39 +08:00
|
|
|
return config
|
2021-02-28 14:50:52 +08:00
|
|
|
},
|
|
|
|
(error) => {
|
2022-02-28 19:09:39 +08:00
|
|
|
Promise.reject(error)
|
2021-02-28 14:50:52 +08:00
|
|
|
}
|
2022-02-28 19:09:39 +08:00
|
|
|
)
|
2020-05-01 21:30:25 +08:00
|
|
|
|
2020-10-20 19:43:11 +08:00
|
|
|
service.interceptors.response.use(
|
2021-02-28 14:50:52 +08:00
|
|
|
(res) => {
|
2022-02-28 19:09:39 +08:00
|
|
|
return res.data ? res.data : Promise.reject(res)
|
2021-02-28 14:50:52 +08:00
|
|
|
},
|
|
|
|
(error) => Promise.reject(error)
|
2022-02-28 19:09:39 +08:00
|
|
|
)
|
2020-05-01 21:30:25 +08:00
|
|
|
|
2022-02-28 19:09:39 +08:00
|
|
|
export default service
|