import axios from 'axios'
import store from '@/store'
// axios.defaults.baseURL
// 由于 后台服务器 拆成了 不同的 业务项目(微服务)
// 所以 需要 使用 若干个 有不同 基地址的 axios对象来分别请求
// 此时,可以通过 axios.create 创建不同配置的 axios对象
const axios1 = axios.create({
baseURL: '',
timeout:5000
})
// 请求拦截器-------------------
axios1.interceptors.request.use((conf) => {
// console.log('请求拦截器:', conf)
// conf.headers.Authorization = 'Bearer '
if (store.state.user) {
conf.headers.Authorization = 'Bearer ' + store.state.user.token
}
return conf
})
// 响应拦截器-------------------
axios1.interceptors.response.use((conf) => {
// console.log('响应拦截器:', conf)
return conf
})
export default axios1
拦截器相关配置
最新推荐文章于 2024-07-14 12:56:18 发布