| | |
| | | import axios from 'axios' // 引入axios |
| | | import qs from 'qs' // 引入qs |
| | | // import store from '@/store' |
| | | import router from '@/router' |
| | | // import router from '@/router' |
| | | import APIUrl from './api.url' // 引入api.url.js |
| | | |
| | | |
| | | // axios 默认配置 更多配置查看Axios中文文档 |
| | | axios.defaults.timeout = 50000 // 超时默认值 |
| | |
| | | // 在ajax发送之前拦截 比如对所有请求统一添加header token |
| | | axios.interceptors.request.use( |
| | | config => { |
| | | config.headers["lang"] = localStorage.getItem("language") ? localStorage.getItem("language") : "zh-CN"; |
| | | if (window.localStorage.getItem("USERTOKEN")) { |
| | | // config.headers.Authorization = `USER_TOKEN = ${store.state.token}`; |
| | | config.headers["USERTOKEN"] = window.localStorage.getItem("USERTOKEN"); |
| | | config.headers['lang'] = localStorage.getItem('language') ? localStorage.getItem('language') : 'zh-CN' |
| | | if (window.localStorage.getItem('USERTOKEN')) { |
| | | // config.headers.Authorization = `USER_TOKEN = ${store.state.token}`; |
| | | config.headers['USERTOKEN'] = window.localStorage.getItem('USERTOKEN') |
| | | } |
| | | console.log(config) |
| | | return config |