如何解决Vue axios请求,浏览器跨域问题

给你一囗甜甜゛ 提交于 2020-02-21 17:42:23
<!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.浏览器报错

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!