首頁 > web前端 > js教程 > 主體

vue-resouce怎麼設定請求頭

php中世界最好的语言
發布: 2018-04-18 09:37:43
原創
2213 人瀏覽過

這次帶給大家vue-resouce怎麼設定請求頭,vue-resouce設定請求頭的注意事項有哪些,下面就是實戰案例,一起來看一下。

第一種:在Vue實例中設定

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

第二種:全域設定請求頭

Vue.http.headers.common['token'] = 'YXBpOnBhc3N3b3Jk';
登入後複製

# 第三種:在攔截器中設定

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

另附vue interceptors 設定請求頭

在main.js加入濾鏡,可以

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;
 });
})
登入後複製

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:



#

以上是vue-resouce怎麼設定請求頭的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!