新建一个services文件
import axios from 'axios'
const $http = axios.create({
baseURL: ''
})
$http.interceptors.request.use(config => {
var xtoken = JSON.parse(window.localStorage.getItem('token'))
// console.log(xtoken)
if (xtoken) {
xtoken = 'Bearer' + xtoken
// console.log(xtoken)
config.headers['Authorization'] = xtoken
}
return config
})
$http.interceptors.response.use(res => {
return res
})
export default $http