1. 程式人生 > >axios關於跨域問題

axios關於跨域問題

axios 跨域

先放報錯資訊:
經過研究N次,是跨域設定問題,

XMLHttpRequest cannot load http://192.168.0.109:8080/farmer/user/register#/. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8081’ is therefore not allowed access.

說一下怎麼解決的
首先我在自己的程式碼中post(url,[config])放了
headers:{“Content-Type”: “application/x-www-form-urlencoded;charset=utf-8”,}
當然這不是影響的重點 也不影響.但是先記錄
重點:後端小夥伴設定Httpresponse.setHeader(Access-Control-Allow-Origin: *)就完事了,= = 把鍋甩給後臺了,

前端有必要的話也可以在config index.js中 找到dev塊 然後來一個 跨域:true 允許跨域 ,
放一個正常請求響應的所有資訊
在這裡插入圖片描述