在向服务器请求数据的时候,经常报这个错
No ‘Access-Control-Allow-Origin’ header is present on the requested resource
解决方法:
在config/index.js中proxyTable添加
proxyTable: {
'/api': { // 要代理的接口名
target: 'http://172.xx.148.xxx:8080/', // 要代理的接口地址
changeOrigin: true, // 允许跨域
pathRewrite: { '^/api': '' } // 接口名重写
},
然后在main.js中声明一个全局
Vue.prototype.HOST = '/api'
可以在组件中使用了
getStudents: function () {
var that = this;
let url = this.HOST +'/cc/json/mobile_tel_segment.htm?tel=153********';
alert(url);
this.$axios.get(url,).then((res)=>{
if(res.status ===200){
let dataContent = res.data.replace('__GetZoneResult_ = ','');//;
that.msg = dataContent;
}
//context.commit('getdata',res)
}).catch((reason)=> {
alert("error");
});