摘要: useEffect 没有依赖项,那它会在每次render之后执行 模拟componentDidMount-useEffect依赖[] 模拟componentDidUpdate-useEffect无依赖,或者依赖[a, b] 模拟componentWillUnMount-useEffect中返回一个函 阅读全文
posted @ 2022-08-01 14:24 不知码 阅读(70) 评论(0) 推荐(0)
摘要: 1.防抖 function debounce(fun, time) { let timers; return function(){ clearTimeout(timers); let arg = arguments; timers = setTimeout( () => { fun.apply(t 阅读全文
posted @ 2022-07-05 19:23 不知码 阅读(19) 评论(0) 推荐(0)
摘要: function arrTrans(num, arr) { // 一维数组转换为二维数组 const iconsArr = []; // 声明数组 arr.forEach((item, index) => { const page = Math.floor(index / num); // 计算该元 阅读全文
posted @ 2022-07-05 19:06 不知码 阅读(59) 评论(0) 推荐(0)
摘要: 1. 对象数组去重 let arr = [ {name: 'mom', id:1}, {name: 'timo', id:2}, {name: 'mom', id:1}, {name: 'timo', id:2}, ] let obj={}; const newarry = arr.reduce( 阅读全文
posted @ 2022-07-05 18:19 不知码 阅读(43) 评论(0) 推荐(0)