欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue-resouce設(shè)置請求頭的三種方法

 更新時間:2017年09月12日 09:48:46   作者:museions  
本篇文章主要介紹了vue-resouce設(shè)置請求頭的三種方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

本文主要介紹了vue-resouce設(shè)置請求頭的三種方法,分享給大家,具體如下:

第一種:在Vue實例中設(shè)置

var vm = new Vue({
  el:'#rrapp',
  data:{
   showList: true,
   title: null
  },
  http: {
    root: '/',
    headers: {
      token: token
    }
  }
})

第二種:全局設(shè)置請求頭

Vue.http.headers.common['token'] = 'YXBpOnBhc3N3b3Jk';

第三種:在攔截器中設(shè)置

Vue.http.interceptors.push((request, next) => {
    request.headers.set('token', token); //setting request.headers
    next((response) => {
      return response
   })
})

另附vue interceptors 設(shè)置請求頭

在main.js添加過濾器,可以

Vue.http.interceptors.push((request,next)=>{
 //request.credentials = true; // 接口每次請求會跨域攜帶cookie
 //request.method= 'POST'; // 請求方式(get,post)
 //request.headers.set('token','111') // 請求headers攜帶參數(shù)

 next(function(response){
  return response;

 });
})

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論