1、使用proxy解决fetch中的跨域问题
①、在package.json中进行配置
"proxy": "http://192.168.0.162:8012"
②、请求时直接写地址
2、对fetch的post请求application/json格式
global.$ = {
post: (info) => {
fetch(info.url, {
method: "POST",
mode: "same-origin",
headers: {
// "Content-Type": "application/x-www-form-urlencoded",
"Content-Type": "application/json;charset=UTF-8",
},
body: JSON.stringify(info.body)
}).then(resp => {
return resp.json()
}).then((res) => {
info.success(res);
}).catch(function (e) {
info.error(e);
});
}
}