上一页 1 ··· 3 4 5 6 7 8 9 10 11 下一页
摘要: 渲染流程 首先会执行 render 方法拿到组件的结构 如果拿到的结构是 jsx 则会调用 React.createElement() 生成虚拟 DOM 根据虚拟 DOM 生成真实 DOM 更新流程 组件的 props 或 this.state 发生改变时执行 render() 方法 执行完 ren 阅读全文
posted @ 2021-12-09 21:52 霸哥yyds 阅读(106) 评论(0) 推荐(0)
摘要: Portals基本使用 import React from 'react'; import ReactDOM from 'react-dom' class Modal extends React.Component { render() { return ReactDOM.createPortal( 阅读全文
posted @ 2021-12-07 21:57 霸哥yyds 阅读(163) 评论(0) 推荐(0)
摘要: 严格模式 import ReactDOM from 'react-dom' import React from "react"; import App from "./App"; ReactDOM.render(<React.StrictMode> <App/> </React.StrictMode 阅读全文
posted @ 2021-12-07 21:42 霸哥yyds 阅读(39) 评论(0) 推荐(0)
摘要: Fragments组件使用 import React from 'react'; class App extends React.Component { constructor(props) { super(props); } render() { return ( <React.Fragment 阅读全文
posted @ 2021-12-07 21:32 霸哥yyds 阅读(69) 评论(0) 推荐(0)
摘要: 受控组件 import React from 'react'; class App extends React.Component { constructor(props) { super(props); this.state = { name: 'xiebenyin' } } render() { 阅读全文
posted @ 2021-12-07 21:18 霸哥yyds 阅读(202) 评论(0) 推荐(0)
摘要: 获取类组件 import React from 'react' class Home extends React.Component { render() { return ( <div>我是类组件</div> ) } } class App extends React.Component { co 阅读全文
posted @ 2021-12-07 00:04 霸哥yyds 阅读(117) 评论(0) 推荐(0)
摘要: 原生方法获取DOM(不推荐) import React from 'react';class App extends React.Component { constructor(props) { super(props); } render() { return ( <div> <h1 id={'b 阅读全文
posted @ 2021-12-06 23:32 霸哥yyds 阅读(981) 评论(0) 推荐(0)
摘要: 不常用的生命周期方法 挂载时 静态方法 static getDerivedStateFromProps 会在 constructor 之后 render 之前调用 static getDerivedStateFromProps 静态方法接收两个参数父组件传递过来的 props 和自身的 state 阅读全文
posted @ 2021-12-05 00:09 霸哥yyds 阅读(42) 评论(0) 推荐(0)
摘要: React生命周期分为3个阶段 挂载时 首先会调用 constructor 创建组件,这里可以通过 props 接收父组件传递过来的数据,可以通过 this.state 初始化组件自己的数据 然后调用 render 渲染组件,主要是返回组件的结构 当组件渲染完毕后调用 componentDidMou 阅读全文
posted @ 2021-12-04 23:31 霸哥yyds 阅读(48) 评论(0) 推荐(0)
摘要: 子组件将数据传递给父组件 import React from 'react'; class Son extends React.Component { constructor(props) { super(props); this.state = { name: 'xiebenyin' } } re 阅读全文
posted @ 2021-12-04 15:03 霸哥yyds 阅读(46) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 下一页