
react
在湖边捡碎花
正在学前端的小白
展开
-
React LazyLoad 图片懒加载
React LazyLoad 图片懒加载先写个lazyload的Js文件 放到src下即可import React from 'react'const threshold = [0.01]class LazyLoad extends React.Component{ constructor(props){ super(props) this.state = { io: null, refs: null,原创 2021-09-01 16:17:45 · 285 阅读 · 2 评论 -
react中解决this指向问题的四种方法
react中解决this指向问题的四种方法一.行间定义事件后面使用bind绑定this run(){ alert("第一种方法!") } <button onClick={this.run.bind(this)}>第一种</button>二.在构造函数内部声明this指向 constructor(props) { super(props); this.state={ //定义数据 } this.run = this.run原创 2021-08-30 09:42:34 · 281 阅读 · 0 评论 -
react生命周期--面试题
react生命周期:componentWillMount 在渲染前调用。componentDidMount 在第一次渲染后调用。componentWillReceiveProps 在组件接收到一个新的props时被调用。这个方法在第一次渲染时不会被调用。shouldComponentUpdate 返回一个布尔值。在组件接收到新的props或state时被调用。在初始化时或者使用forceUpdate时不被调用。可以在你确认不需要更新组件时使用。componentWillUpda原创 2021-08-30 09:31:52 · 1028 阅读 · 0 评论