在开发环境下,在package.json中直接设置"proxy":“https://news-at.zhihu.com”,在项目中通过:
fetch('/api/4/news/latest').then(res=>{
return res.json();
}).then(data=>{
console.log(data);
})
是可以成功获取数据的, 但是在package.json如下设置:
"proxy": {
"/api": {
"target": "https://news-at.zhihu.com",
"secure":false
}
}
就会报错,如下:
在线等大神回复