1、問題
????????localhost/:1 Access to XMLHttpRequest at 'xxx'(請求) from origin 'http://localhost:xxx'(本地) has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute
并且請求已經發送成功(net::ERR_FAILED 200 (OK))
2、解決方法(僅針對axios和使用axios封裝)
在請求的時候,如果不需要發送憑據(如 cookies 或 HTTP 認證信息),可以在請求中禁用?withCredentials
即在請求的時候,如果是get請求,在第二個參數的位置添加 {?withCredentials: false // 禁用憑據
}
????????axios.get('xxx', {?withCredentials: false // 禁用憑據})
????????????????.then(res=> console.log(res.data))
????????????????.catch(error => console.error('Error:', error));