/**
* 网络请求的封装
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
export default class netUntil extends Component {
//Get请求
get(url,successCallback,failCallback){
//fetch请求
fetch(url,{
method:'GET',
})
.then((response) => repsonse.json())//转为json数据
.then((responseData) => {
successCallback(responseData);//请求成功的回调函数
})
.catch((error) => {
failCallback(error);//请求失败的回调函数
});
}
//post请求
post(url,formData,headers,successCallback,failCallback){
//fetch请求
fetch(url,{
method:'POST',
headers:headers,
body:JSON.stringify(formData)
})
.then((response) => response.json())
.then((responseData) => {
successCallback(responseData);
})
.catch((error) => {
failCallback(error);
});
}
}
module.exports = NetUitl;;
自己封装的RN的网络工具类
最新推荐文章于 2024-01-12 09:01:05 发布