import Vue from 'vue'
import axios from 'axios'
import vueAxios from 'vue-axios'
import { Message } from 'element-ui';

Vue.use(vueAxios, axios)
//创建实例

const service = axios.create({
  timeout: 3000000, //请求时间超出
  withCredentials: true, //是否跨站点访问控制请求
})

//request拦截
service.interceptors.request.use(config => {
  return config
}, error => {
  console.log(error)
  Promise.reject(error)
})

//response拦截器
service.interceptors.response.use(
  response => {
    // let resp = response.data;
    // let result = resp.result || resp.Result
    return response
    // if (result == 'success' || result == 'Success') {
    //     return response
    // } else {
    //     let msg = resp.message ? resp.message : resp.ResultMsg? resp.ResultMsg: resp.Message;
    //     Message.error({ message: msg });
    // }
  },
  error => {
    console.log('err' + error)
    return Promise.reject(error)
  }
)

export default service