React图片懒加载
- 话不多说了,创建一个LazyLoad.js的React组件,然后将下面的代码复制过去:
import React from 'react'
// import './lazyload.css'
// threshold
const threshold = [0.01]
class LazyLoad extends React.Component{
constructor(props){
super(props)
this.state = {
io: null,
refs: null,
images: null,
loading: true
}
this.handleonload = this.handleonload.bind(this)
}
UNSAFE_componentWillMount(){
var {
ImgClassName, src, alt, ImgStyle } = this