<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
window.onload=function(){
new Vue({
el:'#itany',
methods:{
send(){
axios({
method:'get',
url:'/VUE/day02/user.josn',
data:{
firstName: 'Fred',
lastName: 'Flintstone'
}
}).then(function(resp){
console.log(resp);
}).catch(function(resp){
console.log();
});
},
sendGet(){
axios.get('sever.php?name=tom&age=23')
.then(resp=>{
console.log(1);
}).catch(err=>{
console.log(2);
});
}
}
});
}
</script>
</head>
<body>
<div id="itany">
<button @click="send">发送AJAX请求</button>
<button @click="sendGet">GET发送AJAX请求</button>
</div>
</body>
</html>
Access to XMLHttpRequest at ‘file://********user.josn’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.浏览器报错
来源:CSDN
作者:qq_20660515
链接:https://blog.csdn.net/qq_20660515/article/details/104423546