text: import axios from 'axios'
  import { MessageBox, Message } from 'element-ui'
  import store from '@/store'
  import { getToken } from '@/utils/auth'
  
  // create an axios instance
  const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API, // api的baseurl
    timeout: 20000 // 超时时间
  })
  
  // request 拦截器
  service.interceptors.request.use(
    config => {
      if (store.getters.token) {
        config.headers['token'] = getToken() // 让每个请求携带自定义token
      }
      return config
    },
    error => {
      // do something with request error
      console.log(error) // for debug
      return Promise.reject(error)
    }
  )
  
  // response 拦截器
  service.interceptors.response.use(
    response => {
      /**
       * code非20000报错
       * @type {any}
       */
      const res = response.data
      if (res.code !== 20000) {
        Message({
          message: res.message || 'Error',
          type: 'error',
          duration: 5 * 1000
        })
        return Promise.reject('error')
      } else {
        return response.data
      }
    },
    error => {
      console.log('err' + error) // for debug
      Message({
        message: error.message,
        type: 'error',
        duration: 5 * 1000
      })
      return Promise.reject(error)
    }
  )
  
  export default service
  