vue-cli 版本 @vue/cli 4.5.8
使用代理,请求Ypi mock数据,post、put方式会出现 pending 状态直至failed
General :
Referrer Policy: strict-origin-when-cross-origin
且不显示请求的 Request Method、Status Code
如图
解决方法:
在vue.config.js文件的devServer下,proxy配置中增加
```
onProxyReq(proxyReq, req, res, options) {
if (req.body) {
const bodyData = JSON.stringify(req.body)
// incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
proxyReq.setHeader('Content-Type', 'application/json')
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
// stream the content
proxyReq.write(bodyData)
}
}
`
看了下源码:在vue-clie 的clie-service中 proxy时 ,
perpareProxy中 重新设置header,origin为当前的目标地址