Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

vue-resourse的interceptors问题

$
0
0

vue+webpack的基础上应该怎么给请求设置一个header。 代码如下,在main.js里面设置了header,后端获取不到。 Vue.http.interceptors.push(function (request, next) { if(request.url !== ‘http://211.149.193.19:8100/token’){ request.headers.Authorization = 'Bearer ’ + sessionStorage.getItem(‘accessToken’) console.log(request.headers) } this.showLoading = true // console.log(this) // 如果用箭头函数 此处则打印出undefined next(function (response) { response.headers.Authorization = 'Bearer ’ + sessionStorage.getItem(‘accessToken’) if (!response.ok) { this.errorCode = response.status this.showDialog = true } this.showLoading = false return response }); });

I‘m webapp-cnodejs-vue


Viewing all articles
Browse latest Browse all 14821

Trending Articles