1.安装 http-proxy-middleware 模块
yarn add http-proxy-middleware
"http-proxy-middleware": "^1.0.1"
2.在 src 文件夹下 创建 setupProxy.js 文件
const { createProxyMiddleware } = require('http-proxy-middleware'); module.exports = function (app) { app.use( createProxyMiddleware( '/api', { target: 'http://106.13.9.213:9000', changeOrigin: true, pathRewrite: { '/api': '' } } ) ); };
3.页面中调用
async componentDidMount() { let res = await axios.get('/api/admin/category'); console.log(res); }
.