Home >Web Front-end >JS Tutorial >How to set request headers in vue-resouce
This time I will show you how to set the request header in vue-resouce. What are the precautions for setting the request header in vue-resouce. The following is a practical case, let's take a look.
The first one: Set
var vm = new Vue({ el:'#rrapp', data:{ showList: true, title: null }, http: { root: '/', headers: { token: token } } })
in the Vue instance Second type: Set request header globally
Vue.http.headers.common['token'] = 'YXBpOnBhc3N3b3Jk';
The third method: Set
Vue.http.interceptors.push((request, next) => { request.headers.set('token', token); //setting request.headers next((response) => { return response }) })
in the interceptor Attached is vue interceptors to set request headers
Add filter to main.js, you can
Vue.http.interceptors.push((request,next)=>{ //request.credentials = true; // 接口每次请求会跨域携带cookie //request.method= 'POST'; // 请求方式(get,post) //request.headers.set('token','111') // 请求headers携带参数 next(function(response){ return response; }); })
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
The above is the detailed content of How to set request headers in vue-resouce. For more information, please follow other related articles on the PHP Chinese website!