Commit 2c7e8462 by liwk

commit

1 parent 3bf269ed
import axios from 'axios'
import Qs from 'qs'
axios.defaults.withCredentials = true
let config = JSON.parse(window.localStorage.getItem('GLSX_OSS_EQUITY_CONFIG'))
const baseURL = config.axios.baseURL
const service = axios.create({
baseURL: baseURL,
timeout: 60 * 1000, // 请求超时时间
transformRequest: [function(data) {
return Qs.stringify(data)
}],
})
service.interceptors.request.use(
config => {
return config
}
)
service.interceptors.response.use(
response => {
const dataAxios = response.data
// 这个状态码是和后端约定的
const { code } = dataAxios
// 有 code 代表这是一个后端接口 可以进行进一步的判断
if (code == -1) {
return dataAxios
}
switch (+code) {
case 0:
return dataAxios
case 20:
case 21:
break
default:
break
}
},
error => {
console.log(error)
console.log(baseURL)
return Promise.reject(error)
})
export default service
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!