跨域无法请求和发送数据;
在config /webpackDevServer.config.js下
function里添加
proxy:{
"/v1":{
"target":"服务器地址和端口号",
"changeOrigin":true,
pathRewrite:{
'^/v1':''
}
}
}
使用时直接
"/v1/请求的接口"
//react-axios
async postdata(params){
return await axios.post(`/v1/getdata`,{params},
{
headers:{
"content-type": "application/json",
}
}).then((res)=>{
return res.data;
}).catch((error)=>{
message.error('服务器出错')
});
},