webpack+antd+fetch 通讯
1. 引入安装fetch
import "whatwg-fetch"
import "es6-promise"
2. 在utils中配置fetch文件,定义了一个get请求和post请求的方法,因为内部是promise封装的所以返回的是一个promise对象,通过.then接收
具体代码
get 方法
export function get(url){
return fetch(url,{
method:'GET',
headers:{
'Accept':'application/json,text/plain,*/*',
'Content-Type':'application/x-www-form-urlencoded',
},
cache:"default",
mode: "cors"
}).then(function(response){
// 捕获状态码和json数据
if(response.status==200){
// response 是浏览器请求报文, response.json()是经过json序列号后,接口返回的内容
return response.json()
}
}).then(f