<!-- 周总结 -->
1. 学了什么?
1.1 ReactJs
1.1.1 React JSX基本语法
render() {
return <div></div>
}
1.1.2 React组件,类组件,复合组件
组件首字母必须大写
类组件中的方法内部不绑定this,在方法内部使用this,需要用bind(this)传入
this.xxx.bind(this)
1.1.3 React组件通信。单向数据流 props, state
props属性,一般传递的是不变的数据
state状态,一般传递可变的数据,也就是根据用户行为来改变state
state发生变化,会调用rendern()方法,重新渲染视图。
.setState() 设置state
1.1.4 React事件。使用驼峰命名法
<div onClick={xxx}></div>
1.1.5 React组件生命周期以及对应的钩子函数
componentWillMount() 组件挂载到真实DOM之前触发
componentDidMount() 组件挂载到真实DOM之后触发
componentWillUpdate() 接收到新的props或state之前触发
componentDidUpdate() 接收到新的props或state之后触发
componentWillUnmount() 组件销毁之前触发
1.16 React-Router,路由,本质上是对 history对象的封装。简单来说就是地址
<Link to="/xxx" />
路由使用 Link定义,to属性指向要跳转到的地址,在实际DOM中,Link会被渲染成一个a标签。
<HashRouter>
<Route path="/xxx" component={xxx} />
</HashRouter>
HashRouter是一个Router的顶层对象,管理相关路由
Route定义单个路由,path属性定义路径,component属性定义路径的指向。
1.1.7 Redux 状态管理,用于解决复杂环境下的多组件通信
store对象: createStore( reducer ) 创建 store 对象
.getState() 获取state
.dispatch( action ) 发送action
.subscribe() 监听state变化,重新渲染视图
view —> store.dispatch({type: xxx}) —> reducer(state, action) —> store.subscribe(xxfn) —> update view
1.2 ECMAScript2015
1.2.1 ES6中的变量声明,新增let,const声明方式
let,声明块级作用域变量
const,声明常量
1.2.2 ES6函数扩展
let a = () => {}
箭头函数,相当于ES5中的匿名函数;var a = function() {}
需要注意的是,箭头函数中不绑定this,箭头函数中的this紧紧跟随其运行环境中的this指向。
...types,动态参数,相当于ES5中的arguments对象
需要注意的是,它们本质上的区别。arguments属于对象;...types属于数组
1.2.3 解构赋值
let obj = {a:11, b:22};
let {a, b} = obj;
console.log(a); // 11
let arr = ['aa', 'bb', 'cc'];
let [a, b, c] = arr;
console.log(a); // 'aa'
2. 做了什么?
2.1 ReactJs 相关demo
2.4 ES6相关demo
2.3 React-Router 相关demo
2.4 Redux 相关demo
3. 有啥问题?
没啥大问题,主要还是不熟悉,思路捋通了多写几遍就好了。
4. 有啥收获?
4.1 对ES6语法,特性进一步加深理解运用
4.2 学会基本运用ReactJs