UNPKG

imobile_for_reactnative

Version:

iMobile for ReactNative,是SuperMap iMobile推出的一款基于React-Native框架的移动应用开发工具。基于该开发工具,用户可以使用JavaScript开发语言,开发出在Android和IOS操作系统下运行的原生移动GIS应用,入门门槛低,一次开发,处处运行。

42 lines (35 loc) 920 B
import { Methods } from "../iServer/url" type ParamType = { [name: string]: any, } type RequestParams = { body?: ParamType, headers?: ParamType, } export default function request(url: string, method: Methods = 'GET', params?: RequestParams) { const body = params?.body const headers = params?.headers let extraData = { headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, method, } if (headers) { extraData.headers = Object.assign(extraData.headers, headers) } if (method === 'POST' && body) { extraData = Object.assign(extraData, { body: JSON.stringify(body) }) } if (method === 'PUT' && body) { extraData = Object.assign(extraData, { body: JSON.stringify(body) }) } return fetch(url, extraData) .then(response => { return response.json() }) .then(responseJson => responseJson) .catch(() => { }) }