Request header field userRole is not allowed by Access-Control-Allow-Headers in preflight response.

今使用axios 請求數據過程中遇到同事設置的請求頭,在我請求的接口中部不被允許,於是老是提示Request header field userRole is not allowed by Access-Control-Allow-Headers in preflight response.異常

最後使用transformRequest 幹掉不需要的headers


  axios.get('https://www.baidu.com',{
            transformRequest :[
              (data, headers) => {
                delete headers['userRole'];
                return data;
              }
            ]
          }).then(res => {
            console.log(res)
            this.realData = res.data.data;
          }).catch(err=>{
            console.log(err)
          })
          

在當前操作中移除掉我不需要的header,這樣即獲取了數據又不會影響到其他同事的操作一舉兩得,簡單記錄哈。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章