-
查找node-modules-react-script-coifig-webpackDevServer-proxy命令行
-
配置代码
"proxy": { //配置项
"/api": {//我们可以在这里设置个口令
"target": "https://xxx.com/",//target是api服务器地址
"changeOrigin": true, //这个是是否替换这里一定要写true
"pathRewrite": { //这个是个正则匹配
"^/api": "/"
}
}
}
- 使用axios测试请求
import axios from axios
componentDidMount(){
axios.get("/api/101.html").then(res){
console.log(res);
}
}
- 可重新启用