12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import axios from 'axios'
- import { Message } from 'element-ui'
- import Cookies from 'js-cookie'
- import store from '../store'
- const fetchInstance = axios.create({
- baseURL: process.env.VUE_APP_BASE_API
-
- })
- fetchInstance.interceptors.request.use(config => {
-
-
-
- config.withCredentials = true
- return config
- }, error => {
- console.log(error)
- Promise.reject(error)
- })
- fetchInstance.interceptors.response.use(
- response => {
- const res = response.data
- if (res.code !== 20000) {
- Message({
- message: res.message,
- type: 'error',
- duration: 5 * 1000
- })
- return Promise.reject('request error')
- } else {
- return response.data
- }
- },
- error => {
- if (error.message !== 'cancel') {
- console.log('err:' + error)
- Message({
- message: error.message,
- type: 'error',
- duration: 5 * 1000
- })
- }
-
- return Promise.reject(error)
- }
- )
- export default fetchInstance
|