vue每次请求加头部(shiro+vue)

vue

vue每次请求加头部(shiro+vue)

 前后台分离,全局请求加头部

设置全局请求为ajax请求

_axios.interceptors.request.use(

function(config) {

var accessToken = localStorage.getItem('accessToken');

if (accessToken && accessToken !== '') {

config.headers.common['Authorization'] = accessToken;

}

return config;

},

function(error) {

// Do something with request error

return Promise.reject(error);

}

);

// 响应拦截器获取 headers,设置(刷新) Token

// Add a response interceptor

_axios.interceptors.response.use(

function(response) {

// Do something with response data

var accessToken = response.headers['authorization'];

if (accessToken && accessToken !== '') {

localStorage.setItem('accessToken',accessToken);

}

return response;

},

function(error) {

// Do something with response error

return Promise.reject(error);

}

);

posted @ 2019-02-22 09:53 韦邦杠 阅读(...) 评论(...) 编辑 收藏

以上是 vue每次请求加头部(shiro+vue) 的全部内容, 来源链接: utcz.com/z/377832.html

回到顶部