随笔分类 - js
摘要:代码如下 <div onClick={e=>{ e.stopPropagation(); }} /> 这样是能阻止冒泡的 ,e.stopPropagation(); 能正常 执行 但是下面 这样写 是不行的 <div onClick={async (e)=>{ let res = await xxx
阅读全文
摘要:forEach 数组里面 forEach 如果带 await 的话,里面 是并行的 [1,2,3].forEach(async (x) => { await xxx(x) }) 这里面 1 2 3 是 会同时被 xxx 函数处理的 想要并行的话,得写成这样 for (const x of [1, 2
阅读全文
摘要:参考来源 https://stackoverflow.com/questions/31193418/html5-canvas-todataurl-returns-blank https://www.geeksforgeeks.org/how-to-crop-images-in-reactjs/ ht
阅读全文
摘要:如题 要是等数组 处理好 , 再setState 中间 就会卡一段时间 const [list, setList] = useState([]); let arr= [] for (const item of sourceList) { let dd = await solve(item) // 耗
阅读全文
摘要:// 获取 base64 const getFileBase64 = (file: RcFile): Promise<string> => { return new Promise((resolve) => { let reader = new FileReader(); reader.readAs
阅读全文
摘要:设置一个 subject , 然后在组件内定义一个 subscription 想要发送 事件就用 subject.next 订阅就赋值 subject.asObservable().subscribe() 直接看代码 const subject = new Subject<RcFile>(); co
阅读全文
摘要:如下图 大概理解 的就是 immer 操作 的时候 ,把这个对象 给冻上了 ,别人是不能修改的, 但是 immer 在操作的时候 react 可能 也对 对象 进行 操作了, 这个时候 就报错 ,说不能操作 只读对象 解决方法 是 import {setAutoFreeze} from 'immer
阅读全文
摘要:预期 [1,2,3,4,5] => true [1,2,3,5,6] => false 代码 //判断一串数字是否是连续的 const isContinuityNum = (num: number[] | number) => { let array = []; if (num instanceof
阅读全文
摘要:function closestMultiple(n, x) { if (x > n) return x; n = n + parseInt(x / 2, 10); n = n - (n % x); return n; } 测试 closestMultiple(6,5) 5 closestMulti
阅读全文
摘要:新建空项目 使用 yarn init 初始化 一个node 项目 安装 依赖 yarn add typescript -D && yarn add ts-node -D && yarn add tslib @types/node -D 安装 全局 ts-node sudo npm install g
阅读全文
摘要:之前写vue 的时候 可以 在 index.html 里面定义 <script type="text/javascript"> const dudu = "val" </script> 然后直接 在 对应的 .vue 文件引用 变量dudu , 发布了以后 直接 改 index.html 就行 但是
阅读全文
摘要:直接看代码 const isSorted = (nums: number[]) => { return nums.every((x, i) => i 0 || x >= nums[i - 1]) } 如果想判断 是否是单调递减 传数组之前 数组.reverse() 反向一下 就行 测试 const
阅读全文
摘要:用的xlsx 的库 先安装 yarn add xlsx 引用 import * as XLSX from 'xlsx'; 具体 代码 (我这是react 写的 ) <Button type={'primary'} style={{ marginLeft: 10 }} onClick={() => {
阅读全文
摘要:输入 [ { "left": 0, "right": 3 }, { "left": 0, "right": 6 }, { "left": 6, "right": 9 }, { "left": 6, "right": 12 }, { "left": 0, "right": 14 }, { "left"
阅读全文
摘要:无限嵌套的 tree const tree = [ { key: "parent1", id: "001", children:[{ key: "B", id: "002", children: [{key: "C", id: "003", children: [{key: "D", id: "00
阅读全文
摘要:js 展平数组 拼装成树有很多中 ,百度 找了 其中 一种 const createDataTree = dataset => { const hashTable = Object.create(null); dataset.forEach(aData => hashTable[aData.ID]
阅读全文
摘要:网上 什么 配置 淘宝源 啊 删除 proxy 都跟着做了, 还是没有 效果 稀里糊涂 把 .npmrc 删除了 , 然后 更新 了 npm nodejs 删除了 yarn.lock 给yarn 全局配置 超时时间 yarn config set network-timeout 600000 -g
阅读全文
摘要:像c# 那样 点出来 ,而不是 函数 括号包着 , 比如 想给所有 Object 添加一个 isSuccess 方法 ,可以 这样写 // js 给 object 添加 扩展方法 Object.defineProperty(Object.prototype, "isSuccess", { value
阅读全文