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 ...
随机推荐
- php_curl.dll libssh2.dll 始终无法加载的原因 及解决办法
在StackOverflow得到最终原因及解决办法 http://stackoverflow.com/questions/16424117/php-unable-to-load-php-curl-dl ...
- 编码规范<1>
目录: 1 排版 2注释 3标识命名 4可读性 1排版 1-1程序使用UTF-8的编码方式 1-2使用空格作为缩进 , 尽量不要使用tab 1-3相对独立的程序块之间,变量说明之后必须加空格 . 例如 ...
- MySQL 存储php中json_encode格式中文问题及解决
MySQL 存储php中json_encode格式信息 ,遇到中文时, 会变成一堆类似uxxxx信息. 1. 原因分析:在存储到数据库时!MySQL 不会存储 unicode 字符: MySQL 仅 ...
- AppSettings和ConnectionStrings的区别
AppSettings是ASP.NET1.1时期用的,在.NET Framework 2.0中,新增了ConnectionStrings. 1.<connectionStrings> &l ...
- 【转载】如何在德州仪器网站查找和下载PCB封装
德州仪器的网站做得相当不错,查找IC资料和下载IC封装样样给力.那么如何在TI网站上能够快速查找到自已需要的PCB封装呢?下面我来告诉你. 1. 在浏览器中输入网址http://weben ...
- go——beego的数据库增删改查
一直都不理解使用go语言的时候,为什么还要自己去装beego,以为使用go便可以解决所有的问题,结果在朋友的点拨下,才意识到: go与beego的关系就好比是nodejs与thinkjs的关系,因此也 ...
- vue.js——初体验
看到最近很火的vue.js,于是开启了自己人生中首篇翻译之路,才意识到这个纯英文版的的确没有中文的通俗易懂~~~~~~不过, 还是硬着头皮把这篇英文版的博客给翻译完了,希望可以帮助自己的同时也方便别人 ...
- Excel中连接函数CONCATENATE()
直接API: CONCATENATE 函数语法具有下列参数 (参数:为操作.事件.方法.属性.函数或过程提供信息的值.): Text1 必需. 要连接的第一个文本项. Text2, ... 可选. 其 ...
- cookie与sessionID之间的关系实验
上一篇介绍了cookie,这里来看看cookie与sessionID之间有什么关系. 一.编写测试用例代码 新建一个servlet如下: public class SessionServlet ext ...
- FZU 2032 Log函数问题 模拟小数加法
题目链接:Log函数问题 2 / 49 Problem G FZU 2032 Log函数问题 不知道为什么...比赛时高精度难倒了一票人...成功搞出大新闻... 试了一下直接double相加超时,然 ...