React组件,React和生命周期
笔记,具体可以看看这个博客:
https://segmentfault.com/a/1190000004168886?utm_source=tag-newest
react 的jsx document.createElement()一层层cereateElement 问题一:jsx render函数原理? 一:
引入:
react.js
react-dom.js
browser.min.js <script type="text/babel">
var destination = document.querySelector("#container"))
ReactDOM.render(
<div>hello world</div>
,destination
)
</script> 二,创建组件,React.createClass({ render:function()
{
return (
<div>hello world</div> ) } }) 三:组件的传递只能是父传给亲儿子,不能越级直接传孙子;{...this.props} <p color={this.props.color} size={this.props.size}></p>
等同于:
<p {...this.props}></p> 四:原生接口
getInitialState:function(){
//刷api接口的时候,组件还未渲染
return {
strikes:,
}
}
与this.state.strikes是返回的一个对象。 componentDidMount:function(){
//组件渲染完成,render渲染之前 } this.setState({strikes:this.state.strikes+}) 五:样式设计
render:function(){
var countStytle={
color:this.props.color,
fontSize:"14px",
padding:"10px",
backgroundColor:"#EEE" }
return (
<div className="letter" style={countStyle}>hello world</div>
)
} 六:react组件的生命周期 componentWillMount componentDidMount componentWillUnmount componentWillUpdate componentDidUpdate shouldComponentUpdate componentWillReceiveProps 组件接口:
顺序: getDefaultProps:function(){
//组件加载前被调用
//返回的是this.props
} getInitialSate:function(){
//返回的是this.state
} componentWillMount:function(){
//挂载到指定节点之前,会先调用这个函数
} render:function(){
return ()
} componentDidMount:function(){
//组件已经成功滴被浏览器加载了
} ======当setState()后,组件状态对象改变。=========
=====周期顺序===============
shouldComponentUpdate:function(newProps,newState){
//返回true,render
//返回false,不会render,界面不会改变
if(newState.count<){
return true
}else{
return false
}
} componentWillUpdate:function(){
//
rerurn;
} render:function(){
//
} componentDidUpdate:function(){
//
} React组件的生命周期机制:
componentWillUnmount
//节点销毁,从dom拿掉 用到调用Dom的api,把这个组件消亡掉:
ReactDOM.unmountComponentAtNode(destination) =====================
组件属性更改:调用顺序: componentWillReceiveProps:function(newProps){
//当组件的属性一旦更改,调用这个方法
return {};
} shuouldComponentUpdate:function(newProps,newState){
//
} componentWillUpdate render 绘制完成。 componentDidUpdate
略。
React组件,React和生命周期的更多相关文章
- 《React Native 精解与实战》书籍连载「React Native 中的生命周期」
此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...
- React Native 中 component 生命周期
React Native 中 component 生命周期 转自 csdn 子墨博客 http://blog.csdn.net/ElinaVampire/article/details/518136 ...
- react实战 系列 —— React 的数据流和生命周期
其他章节请看: react实战 系列 数据流和生命周期 如何处理 React 中的数据,组件之间如何通信,数据在 React 中如何流动? 常用的 React 生命周期方法以及开源项目 spug 中使 ...
- Android四大基本组件介绍与生命周期
Android四大基本组件介绍与生命周期 Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器 ...
- vue生命周期及使用 && 单文件组件下的生命周期
生命周期钩子 这篇文章主要记录与生命周期相关的问题. 之前,我们讲到过生命周期,如下所示: 根据图示我们很容易理解vue的生命周期: js执行到new Vue() 后,即进入vue的beforeCre ...
- Django组件---Django请求生命周期和中间件
Django组件---Django请求生命周期和中间件 Django请求生命周期 说明: client代表浏览器,浏览器的内部为我们封装了socket,Django的WSGI模块也为我们封装了sock ...
- React Native 学习-组件说明和生命周期
组件的详细说明(Component Specifications) 当通过调用 React.createClass() 来创建组件的时候,你应该提供一个包含 render 方法的对象,并且也可以包含其 ...
- react系列(一)JSX语法、组件概念、生命周期介绍
JSX React中,推出了一种新的语法取名为JSX,它给了JS中写HTML标签的能力,不需要加引号.JSX的语法看起来是一种模板,然而它在编译以后,会转成JS语法,只是书写过程中的语法糖. JSX的 ...
- 前端笔记之React(四)生命周期&Virtual DOM和Diff算法&日历组件开发
一.React生命周期 一个组件从出生到消亡,在各个阶段React提供给我们调用的接口,就是生命周期. 生命周期这个东西,必须有项目,才知道他们干嘛的. 1.1 Mouting阶段[装载过程] 这个阶 ...
- React(v16.8.4)生命周期详解
当前版本v16.8.4 装载过程(组件第一次在DOM树中渲染的过程): constructor(常用) -> getInitialState(v16.0已废弃) -> getDefault ...
随机推荐
- Kafka usecase
h1, h2, h3, h4, h5, h6, p, blockquote { margin: 5px; padding: 5; } body { font-family: "Helveti ...
- iOS 禁止手势滑动翻页
- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; // 禁用 iOS7 返回手势 if ([self.navi ...
- mysql补充(4)数据完整性
数据完整性(Data Integrity)是指数据的精确性(Accuracy) 和可靠性(Reliability).(补充mysql数据完整性和约束) 它是应防止数据库中存在不符合语义规定的数据和防止 ...
- Ubuntu 16.04系统下解决Vim乱码问题
方法: 打开终端输入:vim /etc/vim/vimrc,进入编辑模式,加入如下配置: set fileencodings=utf-8,gb2312,gbk,gb18030 set termenco ...
- Spark2 Dataset之视图与SQL
// 创建视图 data.createOrReplaceTempView("Affairs") val df1 = spark.sql("SELECT * FROM Af ...
- CAT偶现NPE的问题
1.背景 我们公司的调用链系统是基于大众点评的CAT客户端改造的,服务端完全有自己设计开发的.在是用CAT客户端收集dubbo调用信息的时候,我们发现了一个CAT偶现NPE的bug,该bug隐藏的很深 ...
- codeforces 894B - Ralph And His Magic Field - [数学题]
题目链接:https://cn.vjudge.net/problem/CodeForces-894B Ralph has a magic field which is divided into n × ...
- MyBatis学习(一)一个简单的例子
mybatis入门例子 开发步骤: 1.创建java工程 2.加入jar包(依赖包.驱动包) 3.创建sqlMapConfig.xml 4.创建数据库,数据库表USER_C,插入测试记录 5.创建PO ...
- CodeForces - 847B Preparing for Merge Sort 二分
http://codeforces.com/problemset/problem/847/B 题意:给你n个数(n<2e5)把它们分成若干组升序的子序列,一行输出一组.分的方法相当于不断找最长递 ...
- 源码 time sleep
C:\Users\Administrator\.PyCharm2017.1\system\python_stubs\2083891348\time.py def sleep(seconds): # r ...