You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
import axios from 'axios'
|
|
// import { Message } from 'element-ui'
|
|
console.log('window.g.ApiUrl', window.g.ApiUrl)
|
|
// 创建axios实例
|
|
const service = axios.create({
|
|
// baseURL: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_BASE_API : '/', // api 的 base_url
|
|
// baseURL: process.env.VUE_APP_BASE_API, // api 的 base_url
|
|
timeout: 1000 * 30, // 请求超时时间
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
})
|
|
|
|
// request拦截器
|
|
service.interceptors.request.use(
|
|
config => {
|
|
// if (getToken()) {
|
|
// config.headers['Authorization'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
// }
|
|
switch (config.urlType) {
|
|
case 'local':
|
|
config.url = (process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API) + config.url
|
|
break
|
|
case 'interlib':
|
|
config.url = (process.env.NODE_ENV === 'production' ? window.g.LibUrl : process.env.VUE_APP_LIB_API) + config.url
|
|
break
|
|
}
|
|
const token = '' // 登录后生成用于识别用户身份,项目不需要直接去掉
|
|
config.headers['Authorization'] = token || ''
|
|
return config
|
|
},
|
|
error => {
|
|
console.error('error: ', error)
|
|
Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
// response 拦截器
|
|
service.interceptors.response.use(
|
|
response => {
|
|
return response.data
|
|
},
|
|
error => {
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
export default service
|