axios接口数据获取报错

<template>
<div>
    <P>axios的数据:{{mess}}</P>
</div>
</template>
<script>
import child from './input-li.vue';

export default{
    components:{
        child
    },
    data(){
        return {
            sContent:"This is hello components",
            username:'',
            mess:'不成功'
        }
    },
    mounted(){
        this.crea();
    },
    methods:{
        crea(){
            this.$axios.get("http://api.telojob.com/v1/job/show/6")
                .then((rsp)=> {
                    this.mess = rsp.data.data.position_name;
 //                        console.log(rsp);
                    alert(rsp);
                })
        },
        userNameChange(){
            this.$store.state.user_name = this.username;
        },
        submit(){
            this.$store.commit("showUserName"); //submit方法指派到showUserName方法
        }
    }
}
 </script>

json数据:

{
"code": "200",
"message": "查询成功!",
"data": {
    "position_name": "开发工程师"
}
}

报错提示:XMLHttpRequest cannot load http://api.telojob.com/v1/job... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8083' is therefore not allowed access.
这是神马情况??

阅读 4.1k
4 个回答

跨域了,让你们后端处理下。

No 'Access-Control-Allow-Origin' 这种错误很明显是跨域了,浏览器的默认安全机制,在本地开发过成中解决跨域有两种方式
1.利用nginx做代理转发
2.把浏览器的安全等级降到最低

推荐问题
宣传栏