Vue axios cross-domain request problem

1.vue axios cross-domain request, the backend has been configured to allow cross-domain, and the agent also reported an error when accessing the cross-domain
2. Is the proxy access address configured or localhost

< hr >

axios.defaults.headers.common ["Access-Control-Allow-Origin"] = "*";
axios.defaults.headers.post [" Content-Type"] = "application/x-www-form-urlencoded";

< hr >

proxyTable: {

  "/apis": {
    target: "http://192.168.1.109/xxx/aa", 
    changeOrigin: true,
    pathRewrite: {
      "^/apis": "" 
      }
  }
}


< hr >

this.$http.post ("/ apis/bbb/cccc", {

)
  json:JSON.stringify({})
})
.then(function (response) {
  console.log(response);
})
.catch(function (error) {
  console.log(error);
});

3. An error was reported in the request result

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

Error: Request failed with status code 404

at createError (createError.js?16d0:16)
at settle (settle.js?db52:18)
at XMLHttpRequest.handleLoad (xhr.js?ec6c:77)
Mar.22,2021

you also need to set Access-Control-Allow-Headers , set to this value Access-Control-Allow-Headers, Origin,Accept, XmurmurRequestedWirth, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers try

see https://stackoverflow.com/que.


you report this error because Access-Control-Allow-Origin is added to your request in addition to the secure header field. The background does not allow this field
solution
background configuration response header Access-Control-Allow-Headers add Access-Control-Allow-Origin

Menu