ajax 拦截器设置请求头


使用vue-resource时,往headers里添加token后,post方法会自动变成options?

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(); });


放在main.js 文件里面


Vue.http.interceptors.push(function(request, next) {
// modify headers
request.headers.set('Accept', 'application/json');
request.headers.set('Authorization', 'Bearer '+ JSON.parse(localStorage.getItem('token')));
// continue to next interceptor
next();
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM