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 ...
随机推荐
- 《Java程序设计》实验二 实验报告
实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验要求 1.没有Lin ...
- QMessageBox中按钮的汉化
方法一:直接添加汉语按钮: QMessageBox mess(QMessageBox::Question, "删除提示", "确认删除所选组件?", NULL) ...
- arcgis API for javascript 学习笔记
ArcGis Server地图是缓存的,意味着它有服务器管理员简历提示性能的一组预先渲染的切片.由于这个原因地图通过ArcGISTiledMapServiceLayer表示 如果地图服务没有一个可用的 ...
- Java 集合系列 11 hashmap 和 hashtable 的区别
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- 必须关注的25位知名JavaScript开发者
必须关注的25位知名JavaScript开发者 发表于2012-08-07 17:30| 16215次阅读| 来源Crossrider Blog| 46 条评论| 作者Crossrider Blog ...
- 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 ...
- C#学习笔记思维导图 一本书22张图
阅读的书是<21天学通C#>博客中有下载 看看总结之后的模块 全部文件 初步展示 数据存储 继承模块 暂时就这些吧 全部思维导图22张打包下载
- Qt 制作安装包
Qt 制作在线.离线 安装包 见如下文档
- BroadcastReceiver的简介
BroadcastReceiver本质上属于一个监听器,因此实现BroadcastReceiver的方法只要重写BroadcastReceiver的onReceive(Context context ...
- NOIP2005 等价表达式 解题报告
明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的要求是判断选项中哪些代数表达式是和 ...