上一页 1 2 3 4 5 6 7 8 9 10 ··· 49 下一页
摘要: type A = { a: number, b: number } type B = { a: number } // 交叉类型, 需要满足A和B的并集 const D: A & B = { a: 1, b: 2 } // 联合类型,需要满足A和B的交集 const E: A | B = { a: 阅读全文
posted @ 2022-06-21 11:07 IslandZzzz 阅读(56) 评论(0) 推荐(0) 编辑
摘要: 定义useLazyLoad 思路: 判断图片在视口内就加载,即: 元素距离页面顶部的距离offsetTop < 滚动条高度scrollTop + 视口高clientHeight import { useCallback, useEffect, useState } from 'react' impo 阅读全文
posted @ 2022-06-21 00:20 IslandZzzz 阅读(969) 评论(0) 推荐(0) 编辑
摘要: 定义 import { useCallback, useEffect, useRef } from "react" export interface ThrottleRefType { fn: Function, timer?: NodeJS.Timeout } export type Thrott 阅读全文
posted @ 2022-06-21 00:14 IslandZzzz 阅读(929) 评论(0) 推荐(0) 编辑
摘要: 定义 import { useCallback, useEffect, useRef } from "react" export interface DebounceRefType { fn: Function, timer?: NodeJS.Timeout } export type Deboun 阅读全文
posted @ 2022-06-21 00:12 IslandZzzz 阅读(971) 评论(0) 推荐(0) 编辑
摘要: 问题 不能将类型“Timeout”分配给类型“number” Type 'Timeout' is not assignable to type 'number'. 解决方案 设置类型为NodeJS.Timeout 清除时使用delete ref.timer + clearTimeout export 阅读全文
posted @ 2022-06-21 00:05 IslandZzzz 阅读(3824) 评论(0) 推荐(0) 编辑
摘要: 问题: "this" 隐式具有类型 "any",因为它没有类型注释 'this' implicitly has type 'any' because it does not have a type annotation 解决方案: 将this放在函数参数列表上声明类型即可,使用的时候this不会干扰 阅读全文
posted @ 2022-06-20 23:21 IslandZzzz 阅读(13042) 评论(0) 推荐(1) 编辑
摘要: setTimeout 模拟实现 setInterval js单线程,在线程占用时间较长的情况下,setInterval可能会向任务队列里添加很多宏任务 这些宏任务在线程空下来的时候,会依次执行,而不会间隔执行,导致失效 所以使用setTimeout+递归来模拟,只有前一次任务执行了之后,才添加下一次 阅读全文
posted @ 2022-06-20 01:06 IslandZzzz 阅读(350) 评论(0) 推荐(0) 编辑
摘要: for (var index = 1; index < 5; index++) { ((i) => { setTimeout(() => { // console.log(i); }, 1000 * i); })(index) } for (let index = 1; index < 5; ind 阅读全文
posted @ 2022-06-19 17:01 IslandZzzz 阅读(371) 评论(0) 推荐(0) 编辑
摘要: // 红黄绿: 使用异步编程方案, promise, async await等都行 // 循环打印: 一轮打印完了以后递归重复这一过程 const taskRunner = (light, timeout) => { return new Promise((resolve) => { setTime 阅读全文
posted @ 2022-06-19 16:53 IslandZzzz 阅读(375) 评论(0) 推荐(0) 编辑
摘要: 先找到根(父)节点,然后根据根节点的id和数组元素的pid找到对应父子关系 重复上一步骤 const getTree = (root, list) => { if(!Array.isArray(list)) throw 'list must be Array' root = root || list 阅读全文
posted @ 2022-06-19 16:41 IslandZzzz 阅读(124) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 49 下一页
点击右上角即可分享
微信分享提示