这几天因为赶时间 , 所以理解上可能有许多的误差 , 如果你不幸点进来了 , 请不要看我的代码 , 这几天我会重新修改 , 然后把错误的不足的 全部修正一下 .

/hwr/src/index.js

  1. import React from 'react';
  2. import ReactDOM from 'react-dom'; // Choose a file from the path
  3. import Detail from './pages/Detail'; //Automatic search path
  4. import { Router, Route, IndexRoute } from 'react-router';
  5. import createHistory from 'history/lib/createHashHistory';
  6. import List from './pages/List';
  7.  
  8. ReactDOM.render(
  9. <Router history={createHistory({ queryKey: false })}
  10. onUpdate={() => window.scrollTo(0, 0)}>
  11. <Route path="/" component={ List } />
  12. <Route path="/detail/:repo" component={ Detail } />
  13. </Router>,
  14. document.getElementById('app')
  15. );
  16.  
  17. // 9 /* 创建历史记录 . 访问网页的记录 */
  18. //11 /* 如果域名下面的是 / 的话就调用 list这个文件 开始渲染页面 */
  19. //13 /* 如果域名下面直接是detail的话就讲detail后面的东西传给 repo 并且打开detail文件将 repo 作为参数穿进去 */

/hwr/src/pages/index.js

  1. import React from 'react';
  2. import { Link } from 'react-router';
  3.  
  4. class List extends React.Component {
  5. render() {
  6. return (
  7. <div>
  8. <p>Please choose a repository from the list below.</p>
  9. <ul>
  10. <li><Link to="/detail/react">React</Link></li>
  11. <li><Link to="/detail/react-native">React Native</Link></li>
  12. <li><Link to="/detail/jest">Jest</Link></li>
  13. </ul>
  14. </div>
  15. );
  16. }
  17. }
  18. export default List;
  19.  
  20. // 根据 index 文件来看 , 打开链接之后 首先进入的就是 List 渲染的页面 .
  21.  
  22. // 这一部分的内容就时分的简单了 . 自己 不会的话 , 赶紧 请教一下别人 .

/hwr/src/pages/index.js

  1. import React from 'react';
  2. import ajax from 'superagent';
  3. class Detail extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. name: [],
  8. mode: 'test1',
  9. test1: [],
  10. test2: [],
  11. test3: []
  12. };
  13. }
  14. fetchFeed(type) {
  15. const baseURL = 'http://192.168.1.100:3000';
  16. ajax.get(`${baseURL}/${this.props.params.repo}/${type}`)
  17. //ajax.get(`http://192.168.1.100:3000/${type}`)
  18. .end((error, response) => {
  19. console.dir(response.body[0].url)
  20. if (!error && response) {
  21. this.setState({ [type]: response.body });
  22. } else {
  23. console.log(`Error fetching ${type}`, error);
  24. }
  25. }
  26. );
  27. }
  28. componentWillMount() {
  29. var self = this;
  30.  
  31. self.fetchFeed('test1');
  32. self.fetchFeed('test2');
  33. self.fetchFeed('test3');
  34. }
  35. showcommits() {
  36. this.setState({ mode: 'test1' });
  37. }
  38. showforks() {
  39. this.setState({ mode: 'test2' });
  40. }
  41. showpulls() {
  42. this.setState({ mode: 'test3' });
  43. }
  44. findName(){
  45.  
  46. }
  47. rendercommits() {
  48. return this.state.test1.map((commit, index) => {
  49. const author = commit.author||commit.owner ? commit.author : 'Anonymous';
  50. return (<p key={index}>
  51. <strong>{author}</strong>:
  52. <a href={commit.url}>{commit.url}</a>.
  53. </p>);
  54. });
  55. }
  56. renderforks() {
  57. return this.state.test2.map((fork, index) => {
  58. const owner = fork.author ? fork.author : 'Anonymous';
  59. return (<p key={index}>
  60. <strong>{owner}</strong>:
  61. <a href={fork.url}>{fork.url}</a>
  62. </p>);
  63. });
  64. }
  65. renderpulls() {
  66. return this.state.test3.map((pull, index) => {
  67. const user = pull.author ? pull.author : 'Anonymous';
  68. return (<p key={index}>
  69. <strong>{user}</strong>:
  70. <a href={pull.url}>{pull.url}</a>.
  71. </p>);
  72. });
  73. }
  74. render() {
  75. let content;
  76. if (this.state.mode === 'test1') {
  77. content = this.rendercommits();
  78. } else if (this.state.mode === 'test2') {
  79. content = this.renderforks();
  80. } else {
  81. content = this.renderpulls();
  82. }
  83. return (<div>
  84. <button onClick={this.showcommits.bind(this)}>Show Commits</button>
  85. <button onClick={this.showforks.bind(this)}>Show Forks</button>
  86. <button onClick={this.showpulls.bind(this)}>Show Pulls</button>
  87. {content}
  88. </div>);
  89. }
  90. }
  91. export default Detail;
  92.  
  93. // 3 在 index 文件中的 repo 作为 属性传到了这里的构造函数 props
  94. // 16 this.props.params.repo 调用this下的 , props 属性 , 下的 repo ( 具体是什么我百度了一下 , 但是看的不懂 , 明天问一下老师 . )
  95.  
  96. // 自己分析 15 16 行 很简单 , 17行的error指的是 ajax.get 下载网页是否成功的状态( 我估计应该是储存的网页状态码 例如 200(正常) , 404( 服务器无法提供信息 ) 503 ( 服务器拒绝提供服务 , 爬虫常见 ) ) , response 用于储存 , 下载成功之后 的内容

JS - The react framework的更多相关文章

  1. 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 ...

  2. D3.js(v3)+react框架 基础部分之数据绑定及其工作过程与绑定顺序

    数据绑定: 将数据绑定到Dom上,是D3最大的特色.d3.select和d3.selectAll返回的元素的选择集.选择集上是没有数据的. 数据绑定就是使被选择元素里“含有”数据. 相关函数有两个: ...

  3. immutable.js 在React、Redux中的实践以及常用API简介

    immutable.js 在React.Redux中的实践以及常用API简介 学习下 这个immutable Data 是什么鬼,有什么优点,好处等等 mark :  https://yq.aliyu ...

  4. arcgis api 4.x for js 结合 react 入门开发系列react全家桶实现加载天地图(附源码下载)

    基于两篇react+arcgis的文章介绍,相信大家也能体会两者的开发区别了.在“初探篇”中作者也讲述了自己的选择,故废话不多说,本篇带大家体验在@arcgis/webpack-plugin环境下,使 ...

  5. Vue.js与React的全面对比

    Vue与React的对比 Vue.js与React.js从某些反面来说很相似,通过两个框架的学习,有时候对一些用法会有一点思考,为加深学习的思索,特翻阅了两个文档,从以下各方面进行了对比,加深了对这两 ...

  6. RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景?

    RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景? RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景? - 知乎 https://www ...

  7. 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 的目的是 ...

  8. 网页的cdn引用地址,js,react,bootstrap

    react+----这三个够用了 <script src="https://cdn.bootcss.com/react/15.4.2/react.min.js">< ...

  9. arcgis api 4.x for js 结合 react 入门开发系列初探篇(附源码下载)

    你还在使用 JQuery 或者 Dojo 框架开发 arcgis api 4.x for js 吗?想试试模块化开发吗?随着前端技术的发展,arcgis api 4.x for js 也有了结合 re ...

随机推荐

  1. 《Java程序设计》实验二 实验报告

    实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验要求 1.没有Lin ...

  2. QMessageBox中按钮的汉化

    方法一:直接添加汉语按钮: QMessageBox mess(QMessageBox::Question, "删除提示", "确认删除所选组件?", NULL) ...

  3. arcgis API for javascript 学习笔记

    ArcGis Server地图是缓存的,意味着它有服务器管理员简历提示性能的一组预先渲染的切片.由于这个原因地图通过ArcGISTiledMapServiceLayer表示 如果地图服务没有一个可用的 ...

  4. Java 集合系列 11 hashmap 和 hashtable 的区别

    java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...

  5. 必须关注的25位知名JavaScript开发者

    必须关注的25位知名JavaScript开发者 发表于2012-08-07 17:30| 16215次阅读| 来源Crossrider Blog| 46 条评论| 作者Crossrider Blog ...

  6. php 5.5.1 编译安装过程

    1.下载解压 wget http://au1.php.net/get/php-5.5.1.tar.gz/from/ch2.php.net/mirror tar zxvf php-5.5.1.tar.g ...

  7. C#学习笔记思维导图 一本书22张图

    阅读的书是<21天学通C#>博客中有下载 看看总结之后的模块 全部文件 初步展示 数据存储 继承模块 暂时就这些吧 全部思维导图22张打包下载

  8. Qt 制作安装包

    Qt 制作在线.离线 安装包 见如下文档

  9. BroadcastReceiver的简介

    BroadcastReceiver本质上属于一个监听器,因此实现BroadcastReceiver的方法只要重写BroadcastReceiver的onReceive(Context  context ...

  10. NOIP2005 等价表达式 解题报告

    明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的要求是判断选项中哪些代数表达式是和 ...