axios封装请求拦截器中给Authorization,添加token加Bearer。


axios封装请求拦截器中给Authorization,添加token加Bearer。

main.js

// 设置请求的根路径
axios.defaults.baseURL="http://localhost:8081/api/"
axios.interceptors.request.use(config=>{
  console.log(config)
  const  token_type="Bearer"
  config.headers.Authorization =token_type+ ' '+window.sessionStorage.getItem('token')
  // 在最后必须返回config
  return config
})
Vue.prototype.$http=axios