vue-resourse的interceptors问题
发布于 7 年前 作者 TerrenceFong 4095 次浏览 来自 问答

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 }); });<br/><br/><a class=“from” href=“https://github.com/shinygang/Vue-cnodejs”>I‘m webapp-cnodejs-vue</a>

9 回复

test<br/><br/><a class=“form” href=“https://github.com/shinygang/Vue-cnodejs”>二次开发的 webapp-cnodejs-vue</a>

@TerrenceFong test<br/><br/><a class=“form” href=“https://github.com/shinygang/Vue-cnodejs”>二次开发的 webapp-cnodejs-vue</a>

@TerrenceFong test<br/><br/><a class=“form” href=“https://github.com/shinygang/Vue-cnodejs”>二次开发的 webapp-cnodejs-vue</a>

@TerrenceFong @TerrenceFF test<br/><br/><a class=“form” href=“https://github.com/shinygang/Vue-cnodejs”>二次开发的 webapp-cnodejs-vue</a>

回到顶部