The problem of vue2 cross-domain request

introduce axios.js

methods:
send () {

axios({
    method:"get",
    url:""
}).then(function(resp){
    console.log(resp);
}).catch(resp => {
    console.log("");
});

},

console error No "Access-Control-Allow-Origin" header is present on the requested resource. Origin" http://xxx.com" is therefore not allowed access.

you can request

normally with jquery"s $.getJSON ().
Sep.07,2021

Cross-domain request header need to configure Access-Control-Allow-Origin : ide does not need to do more processing: devserver-proxy


the development environment can configure agents locally to solve cross-domain
. Please refer to Seven
https://codeshelper.com/a/11.
of my previous article. The production environment needs to add response headers in the background Access-Control-Allow-Origin

the getJSON of jq uses jsonp's cross-domain solution. If the interface can be modified, it is recommended to set header, on the server. If you are using someone else's interface, use jsonp

.
Menu