| | |
| | | import axios from 'axios' |
| | | import { MessageBox, Message } from 'element-ui' |
| | | import store from '@/store' |
| | | import { getToken } from '@/utils/auth' |
| | | |
| | | import { getCookie, getToken } from '@/utils/auth' |
| | | // create an axios instance |
| | | |
| | | const service = axios.create({ |
| | | baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url |
| | | // withCredentials: true, // send cookies when cross-domain requests |
| | | withCredentials: true, // send cookies when cross-domain requests |
| | | timeout: 5000 // request timeout |
| | | }) |
| | | // axios.defaults.withCredentials = true |
| | | |
| | | // request interceptor |
| | | service.interceptors.request.use( |
| | | config => { |
| | | // do something before request is sent |
| | | |
| | | if (store.getters.token) { |
| | | // let each request carry token |
| | | // ['X-Token'] is a custom headers key |
| | | // please modify it according to the actual situation |
| | | config.headers['X-Token'] = getToken() |
| | | if (getCookie('admin')) { |
| | | // let each request carry token |
| | | // ['X-Token'] is a custom headers key |
| | | // please modify it according to the actual situation |
| | | // config.headers['X-Token'] = getToken() |
| | | // config.headers['Authorization'] = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId') |
| | | // config.headers['Cookie'] = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId') |
| | | // document.cookie = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId') |
| | | // document.cookie = 'admin' |
| | | } |
| | | return config |
| | | }, |
| | |
| | | /** |
| | | * If you want to get http information such as headers or status |
| | | * Please return response => response |
| | | */ |
| | | */ |
| | | |
| | | /** |
| | | * Determine the request status by custom code |