0
点赞
收藏
分享

微信扫一扫

vue-cli3.0 axios跨域请求代理配置及端口修改


1.安装 ​​axios​
vue add axios
2.项目根目录下新建 ​​vue.config.js​
// vue.config.js
module.exports = {
devServer: {
port: 端口号,
proxy: {
'/apis': {
target: 'https://movie.douban.com/', // target host
ws: true, // proxy websockets
changeOrigin: true, // needed for virtual hosted sites
pathRewrite: {
'^/apis': '' // rewrite path
}
},
}
}
};
3. 重启服务​​npm run serve​
4. *.vue 文件中请求实例
this.axios.get('/apis/ithil_j/activity/movie_annual2017').then(res => {
console.log(res.data)
}, res => {
console.info('调用失败');
})



举报

相关推荐

0 条评论