vue全局設置請求頭 (封裝axios請求)


Vue.http.interceptors.push((request, next) => { 

   // 請求發送前的處理邏輯

  request.headers.set('Authorization',"Bearer " + 想要增加的變量)

  next((response) => {

    // 請求發送后的處理邏輯

    // 根據請求的狀態,response參數會返回給successCallback或errorCallback

    return response

  })

})

封裝請求 也可以設置header

 

export const $post = (url, params) => {
  return axios({
    method: 'post',
    url: url,
    data: params,
    headers: {
      'token':store.state.token
    }
  });
};

export const $get = (url) => {
  return axios({
    method: 'get',
    url: url,
    headers: {
      'token':store.state.token
    }
  });
};

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM