请求拦截器 Axios
请求拦截器
Created: Aug 13, 2020 10:24 PM
分类: 技术点
技术: 拦截器, 请求头
文件: main.js
import axios from 'axios'
// 添加请求拦截器添加token
axios.interceptors.request.use((config) => {
config.headers.authorization = window.sessionStorage.getItem('token')
return config
})
axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'
Vue.prototype.$http = axios
引入axios文件
通过设置axios.interceptors.request.use
的方式来设置所有的请求拦截器,在被发送数据前进行拦截
config
是它的配置参数,这里通过设置authorization,来为他们添加同意的token