加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React中文教程 - Component Lifecycle(组件的生命周期)

发布时间:2020-12-15 04:56:49 所属栏目:百科 来源:网络整理
导读:!DOCTYPE htmlhtmlheadmeta http-equiv='Content-type' content='text/html; charset=utf-8'titleReact | Component Lifecycle/titlescript src="build/react.min.js"/scriptscript src="build/JSXTransformer.js"/scriptstyleh1{font-size:30px;}/style/hea
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<title>React | Component Lifecycle</title>
<script src="build/react.min.js"></script>
<script src="build/JSXTransformer.js"></script>
<style>h1{font-size:30px;}</style>
</head>
<body>
<script type="text/jsx">
/** @jsx React.DOM */
React.renderComponent(<div>Hello,world!</div>,document.body);
setTimeout(function() {
	React.renderComponent(<div>Goodbye,world.</div>,document.body);
},3000);
setTimeout(function() {
	React.renderComponent(<img src="/images/fin.png" />,2000);
setTimeout(function() {
	React.unmountAndReleaseReactRootNode(document.body);
	React.renderComponent(<h1>Hi! EveryBody.</h1>,4000);
</script>
</body>
</html>

React的组件生命周期分别是:Mounting(附加)、Updating(更新)、Unmounting(移出)

  • 使用React.renderComponent()函数把组件附件到已经存在的DOM节点
  • React.renderComponent判断被附加的DOM节点是否已经存在该类型组件,如果存在则更新,否则就做为新组件附件到DOM节点
  • 使用React.unmountAndReleaseReactRootNode()函数直接把当前DOM节点的全部组件移除,这样能避免内存暴增而导致浏览器崩溃


您可以修改并重新发布本文,如果您能留下本文的参考连结,万分谢谢! 如果您对本文存在疑问,欢迎留言或者直接对本文评论,我会在看到的第一时间回复您。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读