Best way to config Global Headers for Get, Post, Patch in VueJS

后端 未结 2 1617
清歌不尽
清歌不尽 2021-02-04 19:19

I\'m new with VueJs, I\'m finding best way to config Global Headers for Get, Post, Patch in VueJS, which is easy to use and strong security. In the current I ju

2条回答
  •  醉话见心
    2021-02-04 19:39

    You can use vue-resource for making http requests and then use interceptors to modify/patch requests.

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

提交回复
热议问题