vue-cli3中的跨域配置
文章目录
在vue.config.js中配置
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
pathRewrite: {
'/api': ''
}
}
}
},
}
修改完这个文件记得重启你的项目
在使用的时候(这里使用axios举例):
比如要访问的是 http://localhost:3000/interface1 这个接口
this.$axios.get('/api/interface1').then(res->{
console.log(res);
})
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论