摘要: React为什么要实现一套自己的事件系统? A:为了兼容各浏览器对事件处理的差异性/ 冒泡和捕获 冒泡:事件从最内层的元素开始,一直向上传播,直到document对象。 捕获:事件从最外层开始,直到最具体的元素。 addEventListener(event, function,useCapture 阅读全文
posted @ 2022-01-04 09:27 webLion200 阅读(189) 评论(0) 推荐(0)
摘要: 方式1:时间片段 将一次性任务划分成多个片段(Fragments),每次只完成一部分。 将10w个彩色点渲染到dom: 生成色块代码: /* 获取随机颜色 */ function getColor(){ const r = Math.floor(Math.random()*255); const g 阅读全文
posted @ 2022-01-04 09:26 webLion200 阅读(478) 评论(0) 推荐(0)
摘要: render阶段做了什么 通过React.CreateElement,生成新的state和props,得到新的element对象。接下来,会对比这一次和上一次渲染的Virtual DOM,只在真正的DOM树中修改差别的部分。 控制render的方法 主要通过两种方式: 从自身控制是否render。如 阅读全文
posted @ 2021-12-10 11:14 webLion200 阅读(176) 评论(0) 推荐(0)
摘要: 只讲解新版本context,v16.3以后版本 类组件和函数组件只在consumer上有区别。 const ThemeContext = React.createContext(null) // 主题颜色Context const theme = { //主题颜色 dark:{ color:'#18 阅读全文
posted @ 2021-12-10 11:12 webLion200 阅读(61) 评论(0) 推荐(0)
摘要: ref对象的创建 类组件 React.createRef class Index extends React.Component{ constructor(props){ super(props) this.currentDom = React.createRef(null) } component 阅读全文
posted @ 2021-12-06 09:38 webLion200 阅读(162) 评论(0) 推荐(0)
摘要: 类组件生命周期 当发现fiber tag = 1时,表示遇到类组件。 /* workloop React 处理类组件的主要功能方法 */ function updateClassComponent(){ let shouldUpdate const instance = workInProgress 阅读全文
posted @ 2021-11-29 08:13 webLion200 阅读(66) 评论(0) 推荐(0)
摘要: React 有两个重要阶段,render 阶段和 commit 阶段,React 在调和( render )阶段会深度遍历React fiber树,目的就是发现不同(diff),不同的地方就是接下来需要更新的地方,对于变化的组件,就会执行render函数。在一次调和过程完毕之后,就到了commit 阅读全文
posted @ 2021-11-29 08:12 webLion200 阅读(204) 评论(0) 推荐(0)
摘要: Class组件 在 class 组件中,除了继承 React.Component ,底层还加入了 updater 对象,组件中调用的 setState 和 forceUpdate 本质上是调用了 updater 对象上的 enqueueSetState 和 enqueueForceUpdate 方法 阅读全文
posted @ 2021-11-29 08:11 webLion200 阅读(249) 评论(0) 推荐(0)
摘要: createElement React.createElement( type, [props], [...children] ) 第一个参数:如果是组件类型,会传入组件对应的类或函数;如果是 dom 元素类型,传入 div 或者 span 之类的字符串。 第二个参数:一个对象,在 dom 类型中为 阅读全文
posted @ 2021-11-29 08:10 webLion200 阅读(59) 评论(0) 推荐(0)
摘要: 启动MySQL服务器 net start MySQL80 或 mysqld --datadir="C:\ProgramData\MySQL\MySQL Server 8.0\Data" 停止MySQL服务器 net stop MySQL80 启动MySQL客户端 mysql -hlocalhost 阅读全文
posted @ 2021-11-14 18:12 webLion200 阅读(18) 评论(0) 推荐(0)