After vue axios configuration server error 'Access-Control-Allow-Origin' header]

After ue project configuration to the server, the request to be successful, the returned data can also be seen in the browser, but the error:

Failed to load http://pre.api.jmxy.mockuai.c...: 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'. Origin 'http://pre.promotion.jmxy.moc...' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

clipboard.png

200. request status code in a browser can be seen in the returned data:

axios I configured as follows:

 
var instance = axios.create({
  baseURL: baseUrl,
  timeout: 1000 * 12, // 创建axios实例,设定超时时间是12s
  withCredentials: true, // 允许携带cookie headers: { "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" } });

Solution:

withCredentials: false, // 允许携带cookie

In axios in this one is set to false on the line, our project is not required to carry a cookie, so the rear end of the previous project did not turn over, I just took over, so he did not know before this sudden question, if you need to carry cookie, I found a lap down, and basically have the following several answers are the same, you need to back-end configuration.

 

Guess you like

Origin www.cnblogs.com/braveLN/p/11424710.html