1- 安装
yarn add http-proxy-middleware —save
2- 配置
在src下新建文件setupProxy.js
const proxy = require('http-proxy-middleware’);
module.exports = function(app) {
app.use(proxy('/api', {
target: "https://h5api.zhefengle.cn”,
secure: false,
changeOrigin: true,
pathRewrite: {
"^/api": “/“
},
})
);
};
3-测试
import axios from ‘axios’;
export const userSignupRequest = (userData) => {
return dispatch=>{
return axios.get("/api/index/index_tab.html?").then(function (response) {
console.log(response);
})
}
};
4-测试结果