import axios from 'axios'
import router from '@/router'
axios.defaults.timeout = 3000
axios.defaults.baseURL = ''
axios.interceptors.request.use(
config => {
// const token = getCookie('名称')
config.data = config.data
config.headers = {
'Content-Type': 'application/json; charset=utf-8'
}
if (config.url === '/api/login/index') {
} else {
if (localStorage.getItem('Authorization')) {
config.headers.Authorizatior = localStorage.getItem('Authorization')
}
}
// if (token) {
// config.params = {'token': token}
// }
return config
},
error => {
return Promise.reject(error)
}
)
axios.interceptors.response.use(
response => {
//返回错误跳转到首页
if (response.data.code === 0) {
router.push({
path: '/',
vue 请求服务器端API接口
最新推荐文章于 2024-01-30 00:53:12 发布