@ -2,10 +2,13 @@ import axios from 'axios'
//https://www.jb51.net/article/246548.htm
//https://www.jb51.net/article/246548.htm
//站点配置
const publicConfig = window . publicConfig
// 创建一个 axios 实例
// 创建一个 axios 实例
const service = axios . create ( {
const service = axios . create ( {
//baseURL: '/api', // 所有的请求地址前缀部分
//baseURL: '/api', // 所有的请求地址前缀部分
//baseURL: publicConfig.BASE_API,
baseURL : publicConfig . BASE_API ,
//baseURL:ahost,
//baseURL:ahost,
timeout : 60000 , // 请求超时时间毫秒
timeout : 60000 , // 请求超时时间毫秒
withCredentials : true , // 异步请求携带cookie
withCredentials : true , // 异步请求携带cookie
@ -30,13 +33,16 @@ service.interceptors.request.use(
// 添加响应拦截器
// 添加响应拦截器
service . interceptors . response . use (
service . interceptors . response . use (
function ( response ) {
function ( response ) {
//console.log(response)
console . log ( response )
// 2xx 范围内的状态码都会触发该函数。
// 2xx 范围内的状态码都会触发该函数。
// 对响应数据做点什么
// 对响应数据做点什么
// dataAxios 是 axios 返回数据中的 data
// dataAxios 是 axios 返回数据中的 data
const dataAxios = response . data
const dataAxios = response . data
// 这个状态码是和后端约定的
// 这个状态码是和后端约定的
const code = dataAxios . reset
const code = dataAxios . reset
if ( code != '1' ) {
return Promise . reject ( response )
}
return dataAxios
return dataAxios
} ,
} ,
function ( error ) {
function ( error ) {