Fetch的使用
import React,{ Component } from 'react';
import {
AppRegistry,
ListView,
Image,
Text,
StyleSheet,
View,
TouchableHighlight
} from 'react-native';
class SimpleNavigationApp extends Component{
constructor(props){
super(props);
this.state = {
title:'',
slug:'',
};
}
fetchData = ()=>{
fetch('http://bbs.reactnative.cn/api/category/3')
.then((response)=>response.json())
.then((jsondata)=>{
this.setState({
title:jsondata.topics[0].title,
slug:jsondata.topics[0].slug,
})
})
.catch((error)=>{
console.warn(error);
});
};
render() {
return (
<View style={{flex: 1, paddingTop: 22}}>
<Text>
RN中文网头条文章:
</Text>
<Text>
{this.state.title}
</Text>
<Text style={styles.bigblue}>
{this.state.slug}
</Text>
<TouchableHighlight onPress={this.fetchData}>
<Text>提交</Text>
</TouchableHighlight>
</View>
);
}};
const styles = StyleSheet.create({
bigblue: {
color: 'blue',
fontWeight: 'bold',
fontSize: 30,
},
red: {
color: 'red',
},
});
AppRegistry.registerComponent('SimpleNavigationApp', () => SimpleNavigationApp);
Fetch的使用的更多相关文章
- Git 少用 Pull 多用 Fetch 和 Merge
本文有点长而且有点乱,但就像Mark Twain Blaise Pascal的笑话里说的那样:我没有时间让它更短些.在Git的邮件列表里有很多关于本文的讨论,我会尽量把其中相关的观点列在下面. 我最常 ...
- git提示:Fatal:could not fetch refs from ....
在git服务器上新建项目提示: Fatal:could not fetch refs from git..... 百度搜索毫无头绪,最后FQgoogle,找到这篇文章http://www.voidcn ...
- sublime 插件推荐: Nettuts+ Fetch
Nettuts+ Fetch github地址:Nettuts-Fetch 在sublime中直接用 ctrl+shift+P -> pci -> Nettuts-Fetch 即可下载 这 ...
- git pull和git fetch的区别
Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge Git fetch origin master git log ...
- Hibernate之加载策略(延迟加载与即时加载)和抓取策略(fetch)
假设现在有Book和Category两张表,表的关系为双向的一对多,表结构如下: 假设现在我想查询id为2的那本书的书名,使用session.get(...)方法: Session session=H ...
- SQL Server 2012提供的OFFSET/FETCH NEXT与Row_Number()对比测试(转)
原文地址:http://www.cnblogs.com/downmoon/archive/2012/04/19/2456451.html 在<SQL Server 2012服务端使用OFFSET ...
- Attempt to fetch logical page (...) in database 2 failed. It belongs to allocation unit xxxx not to xxx
今天一个同事说在一个生产库执行某个存储过程,遇到了错误: Fatal error 605 occurred at jul 29 2014 我试着执行该存储过程,结果出现下面错误,每次执行该存储过程,得 ...
- Fetch:下一代 Ajax 技术
Ajax,2005年诞生的技术,至今已持续了 10 年.它是一种在客户端创建一个异步请求的技术,本质上它不算创新,是一组技术的组合.它的核心对象是 XMLHttpRequest. 简单回顾下历史 19 ...
- 在 JS 中使用 fetch 更加高效地进行网络请求
在前端快速发展地过程中,为了契合更好的设计模式,产生了 fetch 框架,此文将简要介绍下 fetch 的基本使用. 我的源博客地址:http://blog.parryqiu.com/2016/03/ ...
- 解决:error: Cannot fetch repo (TypeError: expected string or buffer)
同步源码,问题重现: Fetching project platform/external/libopus Fetching project repo error: Cannot fetch repo ...
随机推荐
- linux下安装
挂载 1.虚拟机里选择ios文件2.挂载光驱命令: cd / mount /mnt/cdrom/ cd /mnt/cdrom/ ls 卸载 cd /umount /mnt/cdrom/ 安装 XXX. ...
- spilt用法简介
//获取墓位位置 string MWFLMC = "和平区祥和园D组A碑11排"; //得到字符数组 ]; //分割字符数组 sArray1 = MWFLMC.Split(] { ...
- 【CSS3】Advanced1:Rounded Corners
1.Border radius The border-radius property can be used to working clockwise from top-left set border ...
- nyoj VF函数
大意就是: 在1到在10的9次方中,找到各个位数和为固定值s的数的个数, 首先我们确定最高位的个数,为1到9: 以后的各位为0,到9: 运用递归的思想,n位数有n-1位数生成 f(n)(s) +=f( ...
- 我的iOS开发之路
我终于开始写我的第一个cocos2d-iphone程序了.纪念一下 额,这是一个悲伤的故事.其实我从开始准备开发iOS已经好久了,从我装上Xcode开始到现在,应该已经有差不多一年的时间了把. 还记得 ...
- editpuls查找替换通配符
1 \t Tab character. tab符号 2 \n New line. 新的一行(换行符) 3 . Matches any ...
- Spark0.8.0的安装配置
1.profile export SCALA_HOME=/home/hadoop/scala-2.9.3SPARK_080=/home/hadoop/spark-0.8.0export SPARK_H ...
- Codeforces295A - Greg and Array(线段树的成段更新)
题目大意 给定一个序列a[1],a[2]--a[n] 接下来给出m种操作,每种操作是以下形式的: l r d 表示把区间[l,r]内的每一个数都加上一个值d 之后有k个操作,每个操作是以下形式的: x ...
- Microsoft SQL Server Data Tools - Business Intelligence for Visual Studio 2013 http://www.microsoft.com/en-us/download/details.aspx?id=42313
Microsoft SQL Server Data Tools - Business Intelligence for Visual Studio 2013 http://www.microsoft. ...
- hdoj 4612 Warm up【双连通分量求桥&&缩点建新图求树的直径】
Warm up Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Su ...