小编Lau*_*ntL的帖子

如何在React Native中为API请求创建进度条?

当我的程序获取天气数据时,我正在尝试制作一个简单的进度计数器,从0%到100%.API请求是由getLocation()内部index.ios.js调用fetchWeather()weatherApi.js.有没有办法衡量fetch函数对我的API请求的进度?如果没有,实施加载栏的好方法是什么?

weatherAPI.js

const rootUrl ='http://api.openweathermap.org/data/2.5/weather?appid=fcea54d0ceade8f08ab838e55bc3f3c0'

export const fetchWeather = (lat,lon) => {

    const url = rootUrl+'&lat='+lat+'&lon='+lon+"&units=metric"
    console.log(url)

  return fetch(url)
    .then(res => res.json())
    .then(json => ({
        temp: json.main.temp,
        weather: json.weather[0].main
    }))

}
Run Code Online (Sandbox Code Playgroud)

index.ios.js

import React, {Component} from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    StatusBar
    } from 'react-native'

import Icon from 'react-native-vector-icons/Ionicons'
import {fetchWeather} from './weatherAPI'
import Highlight from 'react-native-highlight-words'

const iconNames = {
    Default: 'md-time',
    Clear: 'md-sunny',
    Rain: 'md-rainy',
    Thunderstorm: 'md-thunderstorm',
    Clouds: …
Run Code Online (Sandbox Code Playgroud)

javascript fetch ios reactjs react-native

7
推荐指数
1
解决办法
5693
查看次数

为什么要显示对象数据?

我只是要求页面显示网站的链接,但有些东西正在发送额外的信息. 额外信息在

任何帮助都非常感谢.

ruby ruby-on-rails erb

-8
推荐指数
1
解决办法
61
查看次数

标签 统计

erb ×1

fetch ×1

ios ×1

javascript ×1

react-native ×1

reactjs ×1

ruby ×1

ruby-on-rails ×1