package.json配置跨域的域名
// package.json
{
"proxy": "http://localhost:4000"
}
手动配置跨域
1.安装http-proxy-middleware
npm install http-proxy-middleware --save
2.创建src/setupProxy.js
const proxy = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/api',
proxy({
target: 'http://localhost:4000',
changeOrigin: true
})
)
}