Fetch網(wǎng)絡(luò)請求:get
static get=(url)=>{
????????????????????return new Promise(resolve => {
????????????????????fetch(url)
????????????????????????????.then(response=>response.json())
?????????????????????????????.then(result=>{ resolve(result);?
?????????????????????????????????})?
?????????????????????.catch(error=>{ reject(error); })?
?})
}
Post:
static post=(url,data)=>{
return new Promise(((resolve, reject) => {
????????????????fetch(url,{
? ??????????????????????method:'POST',
? ? ? ? ? ? ? ? ? ? ? ?header:{ 'Accept':'application/json',//接受json格式的返回類型顷链,
?????????????????????'Content-Type':'application/json',
? ?????????????????? body:JSON.stringify(data),
? ? ? ? ? ? ? ? ? .then(response=>response.json())
?????????????????.then(result=>{ resolve(result); })
?????????????????.catch(error=> { reject(error); }) }) )
? }