新版create-react-app+webpack4跨域
src/setupProxy.js 创建文件
const proxy = require('http-proxy-middleware'); module.exports = function(app) { app.use(proxy('/api', { target: 'https://www.easy-mock.com/api/' , secure: false, changeOrigin: true, pathRewrite: { "^/api": "/" }, // http://www.easy-mock.com' // cookieDomainRewrite: "http://localhost:3000" })); };
注意api前面千万别加/,/api/****是错的,还要注意请求的接口是post还是Get
const common='api/mock/5d50cfdbc7a4ef40e1081602/sy'; export const sy_userIndex = data => ly_req(`/${common}/v1/userBaseinfoList`,data,'GET');