JS - The react framework
这几天因为赶时间 , 所以理解上可能有许多的误差 , 如果你不幸点进来了 , 请不要看我的代码 , 这几天我会重新修改 , 然后把错误的不足的 全部修正一下 .
/hwr/src/index.js
import React from 'react';
import ReactDOM from 'react-dom'; // Choose a file from the path
import Detail from './pages/Detail'; //Automatic search path
import { Router, Route, IndexRoute } from 'react-router';
import createHistory from 'history/lib/createHashHistory';
import List from './pages/List'; ReactDOM.render(
<Router history={createHistory({ queryKey: false })}
onUpdate={() => window.scrollTo(0, 0)}>
<Route path="/" component={ List } />
<Route path="/detail/:repo" component={ Detail } />
</Router>,
document.getElementById('app')
); // 9 /* 创建历史记录 . 访问网页的记录 */
//11 /* 如果域名下面的是 / 的话就调用 list这个文件 开始渲染页面 */
//13 /* 如果域名下面直接是detail的话就讲detail后面的东西传给 repo 并且打开detail文件将 repo 作为参数穿进去 */
/hwr/src/pages/index.js
import React from 'react';
import { Link } from 'react-router'; class List extends React.Component {
render() {
return (
<div>
<p>Please choose a repository from the list below.</p>
<ul>
<li><Link to="/detail/react">React</Link></li>
<li><Link to="/detail/react-native">React Native</Link></li>
<li><Link to="/detail/jest">Jest</Link></li>
</ul>
</div>
);
}
}
export default List; // 根据 index 文件来看 , 打开链接之后 首先进入的就是 List 渲染的页面 . // 这一部分的内容就时分的简单了 . 自己 不会的话 , 赶紧 请教一下别人 .
/hwr/src/pages/index.js
import React from 'react';
import ajax from 'superagent';
class Detail extends React.Component {
constructor(props) {
super(props);
this.state = {
name: [],
mode: 'test1',
test1: [],
test2: [],
test3: []
};
}
fetchFeed(type) {
const baseURL = 'http://192.168.1.100:3000';
ajax.get(`${baseURL}/${this.props.params.repo}/${type}`)
//ajax.get(`http://192.168.1.100:3000/${type}`)
.end((error, response) => {
console.dir(response.body[0].url)
if (!error && response) {
this.setState({ [type]: response.body });
} else {
console.log(`Error fetching ${type}`, error);
}
}
);
}
componentWillMount() {
var self = this; self.fetchFeed('test1');
self.fetchFeed('test2');
self.fetchFeed('test3');
}
showcommits() {
this.setState({ mode: 'test1' });
}
showforks() {
this.setState({ mode: 'test2' });
}
showpulls() {
this.setState({ mode: 'test3' });
}
findName(){ }
rendercommits() {
return this.state.test1.map((commit, index) => {
const author = commit.author||commit.owner ? commit.author : 'Anonymous';
return (<p key={index}>
<strong>{author}</strong>:
<a href={commit.url}>{commit.url}</a>.
</p>);
});
}
renderforks() {
return this.state.test2.map((fork, index) => {
const owner = fork.author ? fork.author : 'Anonymous';
return (<p key={index}>
<strong>{owner}</strong>:
<a href={fork.url}>{fork.url}</a>
</p>);
});
}
renderpulls() {
return this.state.test3.map((pull, index) => {
const user = pull.author ? pull.author : 'Anonymous';
return (<p key={index}>
<strong>{user}</strong>:
<a href={pull.url}>{pull.url}</a>.
</p>);
});
}
render() {
let content;
if (this.state.mode === 'test1') {
content = this.rendercommits();
} else if (this.state.mode === 'test2') {
content = this.renderforks();
} else {
content = this.renderpulls();
}
return (<div>
<button onClick={this.showcommits.bind(this)}>Show Commits</button>
<button onClick={this.showforks.bind(this)}>Show Forks</button>
<button onClick={this.showpulls.bind(this)}>Show Pulls</button>
{content}
</div>);
}
}
export default Detail; // 3 在 index 文件中的 repo 作为 属性传到了这里的构造函数 props
// 16 this.props.params.repo 调用this下的 , props 属性 , 下的 repo ( 具体是什么我百度了一下 , 但是看的不懂 , 明天问一下老师 . ) // 自己分析 15 16 行 很简单 , 17行的error指的是 ajax.get 下载网页是否成功的状态( 我估计应该是储存的网页状态码 例如 200(正常) , 404( 服务器无法提供信息 ) 503 ( 服务器拒绝提供服务 , 爬虫常见 ) ) , response 用于储存 , 下载成功之后 的内容
JS - The react framework的更多相关文章
- WHAT IS THE DIFFERENCE BETWEEN REACT.JS AND REACT NATIVE?
Amit Ashwini - 09 SEPTEMBER 2017 React.js was developed by Facebook to address its need for a dynami ...
- D3.js(v3)+react框架 基础部分之数据绑定及其工作过程与绑定顺序
数据绑定: 将数据绑定到Dom上,是D3最大的特色.d3.select和d3.selectAll返回的元素的选择集.选择集上是没有数据的. 数据绑定就是使被选择元素里“含有”数据. 相关函数有两个: ...
- immutable.js 在React、Redux中的实践以及常用API简介
immutable.js 在React.Redux中的实践以及常用API简介 学习下 这个immutable Data 是什么鬼,有什么优点,好处等等 mark : https://yq.aliyu ...
- arcgis api 4.x for js 结合 react 入门开发系列react全家桶实现加载天地图(附源码下载)
基于两篇react+arcgis的文章介绍,相信大家也能体会两者的开发区别了.在“初探篇”中作者也讲述了自己的选择,故废话不多说,本篇带大家体验在@arcgis/webpack-plugin环境下,使 ...
- Vue.js与React的全面对比
Vue与React的对比 Vue.js与React.js从某些反面来说很相似,通过两个框架的学习,有时候对一些用法会有一点思考,为加深学习的思索,特翻阅了两个文档,从以下各方面进行了对比,加深了对这两 ...
- RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景?
RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景? RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景? - 知乎 https://www ...
- MVC、MVP、MVVM、Angular.js、Knockout.js、Backbone.js、React.js、Ember.js、Avalon.js、Vue.js 概念摘录
注:文章内容都是摘录性文字,自己阅读的一些笔记,方便日后查看. MVC MVC(Model-View-Controller),M 是指业务模型,V 是指用户界面,C 则是控制器,使用 MVC 的目的是 ...
- 网页的cdn引用地址,js,react,bootstrap
react+----这三个够用了 <script src="https://cdn.bootcss.com/react/15.4.2/react.min.js">< ...
- arcgis api 4.x for js 结合 react 入门开发系列初探篇(附源码下载)
你还在使用 JQuery 或者 Dojo 框架开发 arcgis api 4.x for js 吗?想试试模块化开发吗?随着前端技术的发展,arcgis api 4.x for js 也有了结合 re ...
随机推荐
- PowerDesigner使用教程|使用方法
PowerDesigner安装方法: http://dev.firnow.com/course/3_program/java/javajs/20090908/174375.html 安装完这2个软件 ...
- Python顺序集合之 tuple
慕课网<Python 入门>学习笔记 1.tuple特性 tuple是另一种有序的列表,中文翻译为“ 元组 ”.tuple 和 list 非常类似,但是,tuple一旦创建完毕,就不能修改 ...
- mysql知识初篇(一)
mysql介绍 (1) mysql数据库是瑞典AB开发. (2) mysql--> sun --> oracle. (3) mysql数据库的特点. 1. 开源. 2. 免费. 3. 跨平 ...
- Java初学之华容道游戏
package hhuarongdao; public class example { public static void main(String args[]) { new Hua_Rong_Ro ...
- MVC中使用HTML Helper类扩展HTML控件
文章摘自:http://www.cnblogs.com/zhangziqiu/archive/2009/03/18/1415005.html MVC在view页面,经常需要用到很多封装好的HTML控件 ...
- WebDataTree 使用XML做数据源绑定数据
英文版原文链接:http://www.infragistics.com/help/topic/e5f07b51-ee2d-4a33-aaac-2f43cffff327 所使用的控件版本为:Infrag ...
- 用户上网的基本流程图与DNS解析原理
1.用户上网发送请求,首先确认本地的hosts中是否含有域名,有则进行ip访问,如果没有呢?看本机的display缓存中有没有访问网站的ip,有就直接去访问 那么如果本地的hosts和缓存都没有呢?这 ...
- java面向对象编程——第四章 类和对象
OO:面向对象 OOP:面向对象编程 OOA:面向对象分析 OOD:面向对象设计 结构化编程:从顶向下,将一个大问题分解成更小的任务,然后为每一个更小的任务编写一个过程.最后程序员会编写一个主过程来启 ...
- Kafka简要图解
LinkedIn贡献的分布式消息系统 - 请参考这里 kafka集群:producer写入消息,consumer读取消息 消息分为不同主题,每个主题可以分为多个partition(并行),每个part ...
- 小记:利用递归调用循环寻找MP3文件的方法。
private void findMp3Data(File mp3file) { File[] filelist = mp3file.listFiles(); if (filelist != null ...