CNode

vue-resourse的interceptors问题

问答
TTerrenceFong发布于10 年前最后回复10 年前9 回复4798 浏览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

查看回复

回复 (9)

B
bhaltair#1·10 年前

测试一下

I
iamnotblank#2·10 年前

用fetch 吧 From Noder

H
huajiang1989#3·10 年前

asdasd

H
huajiang1989#4·10 年前

saasf

T
TerrenceFong#5·10 年前

test二次开发的 webapp-cnodejs-vue

H
huajiang1989#9·10 年前

asdfasdf

参与回复
登录后即可参与回复。登录