0
点赞
收藏
分享

微信扫一扫

十九、Vue之vue-cli3.0跨域问题解决

  在项目的根目录新建一个​​vue.config.js​​文件(和package.json同层次目录),然后配置文件如下:

module.exports = {
devServer: {
proxy: {
// 所有的请求起始部分全部用 '/api'代替,比如访问"https://192.168.1.4/movie",那么简写成"/api/movie"即可
'/api': {
target: 'https://192.168.1.4/', //对应自己的接口
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}

请求数据:

requestData() {
var url = '/api/movie';
this.$http.get(url).then((response) => {
console.log(response);
}, (err) => {
console.log(err);
});
}


举报

相关推荐

0 条评论