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 ...
随机推荐
- windows_xp下卸载office2003报无法打开此修补程序包错误
今天在给公司一同事装完xp系统后.准备卸载预安装的Microsoft office2003,然后安装Microsoft office2007.结果在卸载office2003时报如下错误. 经过上网查询 ...
- 【CF840C】On the Bench DP
[CF840C]On the Bench 题意:给你一个长度为n的数组{ai},定义一个1到n的排列是合法的,当且仅当对于$1\le i <n$,$a_i\times a_{i+1}$不是完全平 ...
- iOS - 开源框架、项目和学习资料汇总(动画篇)
动画 1. Core Animation笔记,基本的使用方法 – Core Animation笔记,基本的使用方法:1.基本动画,2.多步动画,3.沿路径的动画,4.时间函数,5.动画组.2. awe ...
- jQuery里面ajax请求的封装
为了避免ajax漫天飞,我们需要对jQuery的代码进行封装,封装代码: function api_request(name, params, cb, scope, async, el) { if ( ...
- vue之修饰符
修饰符 .lazy 在默认情况下,v-model 在每次 input 事件触发后将输入框的值与数据进行同步 .你可以添加 lazy 修饰符,从而转变为使用 change 事件进行同步: <!-- ...
- git 提示:fatal: remote origin already exists. 错误解决
今天git连接远程库的时候出现fatal: remote origin already exists. 这个错误 大概是之前连接过别的库吧 然后我们的解决办法就是删除之前的连接 1.删除git远程仓库 ...
- ELK之使用filebeat的多行过滤插件把多行合并成一行
java运行日志一般有多行,格式类似如下 格式为:日期 + 日志级别 + 日志信息 有些日志是多行的,需要使用filebeat多行插件把多行合并成一行 未使用多行插件的日志格式 修改filebeat配 ...
- 在ubuntu下安装使用latex
参考:https://www.cnblogs.com/longdouhzt/archive/2012/09/27/2706358.html https://jingyan.baidu.com/albu ...
- CCCC L2-020. 功夫传人 搜索 bfs && 精度+ 特判
https://www.patest.cn/contests/gplt/L2-020 题解:给你一颗树,让你遍历一遍,顺便更新一下数据,每次到根节点时将其对应的数据加到ans上面.这里用的bfs. 坑 ...
- Python面试数据库
1.列举常见的关系型数据库和非关系型都有那些? 关系型 : MySQL,SQL Server ,Oracle , Sybase, DB2 非关系型 : Redis, MongodDB 2.MySQL常 ...