webpack代理--proxy
文章目录
//webpack.config.js
proxy: {
'/drink': {
target: "http://xxx.26.xx.75:8010/channelFreeDrink/",
changeOrigin:true,
pathRewrite: {
'^/drink': ''
}
}
}
//api.js
const sourcelist = ()=>{
return new Promise((resolve,reject)=>{
// fetch(window.YY_API + '/channelFreeDrink/activity').then(res => {
fetch('/drink/activity').then(res => {
if(res.status==200) return res.json()
}).then(data=>{
resolve(data)
})
})
}
图中黄框跟黄框所对应(/drink),白框(/activity)在代理请求的时候会加在target所指的链接后面
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论