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 ...
随机推荐
- [原]secureCRT 改变显示宽度
1.首先全局设置:Options - Global Options - Terminal - Appearance - Maximumcolumns 最大只能设置成1024(推荐256),设置越大越占 ...
- minix中atoi、atol、atof的实现
在minix2.0源代码中,有将字符串类型转换为int.long.double类型的函数实现,相关的实现函数分别在atoi.c.atol.c.atof.c文件中,我们来逐一学习其中的源码: 1.int ...
- iOS - UIScreen的 bound、frame、scale属性
A UIScreen object contains the bounding rectangle of the device’s entire screen. When setting up you ...
- Docker定制容器镜像(利用Dockerfile文件)
1.创建Dockerfile文件 新建一个目录,在里面新建一个dockerfile文件(新建一个的目录,主要是为了和以防和其它dockerfile混乱 ) [root@docker01 myfiles ...
- 近期在看的一段JS(谁能看出我想实现什么功能)
示例代码: <script type="text/javascript"> !function(){ var e=/([http|https]:\/\/[a-zA-Z0 ...
- git 提示:fatal: remote origin already exists. 错误解决
今天git连接远程库的时候出现fatal: remote origin already exists. 这个错误 大概是之前连接过别的库吧 然后我们的解决办法就是删除之前的连接 1.删除git远程仓库 ...
- Thread和Runable的区别、Synchronized锁关键字
一.Thread和Runable的区别 Thread是基类,子类必继承他实现其run方法.其也是实现了Runable接口.Thread是普通的类,并非抽象类或者密封类等. Runnable是接口,子类 ...
- compile time - run-time
php.net Class member variables are called "properties". You may also see them referred to ...
- Arrow-一个最好用的日期时间Python处理库
https://www.jianshu.com/p/c878bb1c48c1 写过Python程序的人大都知道,Python日期和时间的处理非常繁琐和麻烦,主要有以下几个问题: 有众多的package ...
- Maven中的pom.xml配置文件详解
原文:http://blog.csdn.net/u012152619/article/details/51485297 <project xmlns="http://maven.apa ...