1、在使用vue开发的时候经常要涉及到跨域的问题,其实在中是有我们设置跨域请求的文件的。
2、当跨域无法请求的时候我们可以修改工程下文件夹下的中的dev:{}部分。
(''),
,
,
'',
proxyTable:{
'/api':{
target:'http://api.douban.com/v2',
pathRewrite:{
'^/api':''
}
}
},
//CSSSourcemapsoffbydefaultbecauserelativepathsare"buggy"
//withthisoption,accordingtotheCSS-LoaderREADME
//(https://github.com/webpack/css-loader#sourcemaps)
//Inourexperience,theygenerallyworkasexpected,
//justbeawareofthisissuewhenenablingthisoption.
}
将target设置为我们需要访问的域名。
Vue.prototype.HOST='/api'
4、至此,我们就可以在全局使用这个域名了,如下:
varurl=this.HOST+'/movie/in_theaters'
this.$http.get(url).then(res=>{this.movieList=res.data.subjects;},res=>{console.info('调用失败');});
立即下载