vue-resource怎么设置头部的header
用拦截器设置request
Vue.http.interceptors.push((request, next) => {
request.headers['xxx'] = xxx;
next(response => {
...
});
});
Interceptors
Interceptors can be defined globally and are used for pre- and postprocessing of a request. If a request is sent using this.$http or this.$resource the current Vue instance is available as this in a interceptor callback.
Request processing
Vue.http.interceptors.push(function(request, next) {
// modify method
request.method = 'POST';
// modify headers
request.headers.set('X-CSRF-TOKEN', 'TOKEN');
request.headers.set('Authorization', 'Bearer TOKEN');
// continue to next interceptor
next();
});
摘自文档 https://github.com/pagekit/vu...
像一楼说的,vue.resource( 2.0后不再更新)
推荐使用 axios https://github.com/mzabriskie...
详见 帮助文档
https://github.com/pagekit/vu...
推荐使用
https://github.com/mzabriskie...