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 ...
随机推荐
- 常用px,pt,em换算表
pt (point,磅):是一个物理长度单位,指的是72分之一英寸. px (pixel,像素):是一个虚拟长度单位,是计算机系统的数字化图像长度单位,如果px要换算成物理长度,需要指定精度DPI(D ...
- OAuth 的权限问题与信息隐忧
核心提示:以 QQ 登陆和微博登陆为代表的“一键登陆”背后不仅仅是登陆这么简单,它还默认获取了你的其他隐私资料和账号的部分使用权限,我们在享受便利的同时一定不要忘记保护好我们的个人信息安全. 去年3Q ...
- Curl之Post Json
curl Post Json $ curl -i -X POST -H "'Content-type':'application/x-www-form-urlencoded', 'chars ...
- 独立线程中实现QT GUI
在网上搜集的资料: http://www.qtcentre.org/threads/16552-Starting-QT-GUI-in-a-seperate-Threadhttp://stackover ...
- c++/c字符串操作汇集
1. 字符串替换 void string_replace(std::string &strBig, const std::string &strsrc, const std::stri ...
- 【CSS3】Advanced4:Advanced Colors
1.rgba(red,green,blue,alpha(不透明度0.0(完全透明)与 1.0(完全不透明)) 2.HSLa(hue(色调 0red 120green 240blue),saturati ...
- Git 远程分支的查看及相关问题
命令:git ls-remote -t 或者 git ls-remote --tag 运行结果如下: 0975ebc0f9a6b42ecbe066a50a26a678a0753b4d refs/tag ...
- 改进的SMO算法
S. S. Keerthi等人在Improvements to Platt's SMO Algorithm for SVM Classifier Design一文中提出了对SMO算法的改进,纵观SMO ...
- shell常识总结
#!/bin/bash cmd="ls -lt | grep ^d | awk 'NR==1 {print $9}'" $cmd 这是一个获取文件夹名字的脚本,但是却提示: ls: ...
- normalization归一化
简单的举个例子:一张表有两个变量,一个是体重kg,一个是身高cm.假设一般情况下体重这个变量均值为60(kg),身高均值为170(cm).1,这两个变量对应的单位不一样,同样是100,对于身高来说很矮 ...