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