随笔分类 - js
运用js
摘要:import { useCallback, useEffect, useRef } from 'react'; export interface DebounceRefType { fn: Function; timer?: NodeJS.Timeout; } export type Debounc
阅读全文
摘要:方法: const imgSrcQueue: Array<HTMLImageElement> = []; export function preloadImageList(names) { return new Promise((resolve) => { let n = 0, img, imgs
阅读全文
摘要:封装一个可以使用onAppear的<VIew/>组件: import React, { PureComponent } from 'react'; class View extends PureComponent { constructor(props) { super(props); this.t
阅读全文
摘要:适用范围:支付宝,淘宝小程序 效果: 组件目录结构: 详情: index.axml <!-- [{"value":["3","5"],"style":"","isTime":true},{"value":"秒","style":""}] --> <view class="countdown-main
阅读全文
摘要:获取一个特定时间的时间戳,我们的选择有很多,dayjs,moment等,但常规的,我们一般用 new Date()来获取; 比如: 但在ios环境下,以上运行获取的为:NaN; 只有将‘-’改为‘/’才能正确获取其对应时间戳。 如 new Date('2023/03/10 23:59:59').ge
阅读全文
摘要:上代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" conten
阅读全文
摘要:骨骼动画 首先我们想要了解骨骼动画的写法,就得去了解Tiyjs。骨骼动画是基于tinyjs平台二次开发的插件运用。 官网地址: http://tinyjs.net/guide/ 插件种类: 在官网插件平台上,我们似乎可以找到三个有关骨骼动画的插件平台。spine,creature,dragonbon
阅读全文
摘要:场景:比如我们在进行一些图片分享链接时,要进行一些特定连接的字符串拼接。这个时候就需要对我们的链接进行 uri编码操作。比如:百度地址:https://www.baidu.com方法:encodeURIComponent("https://www.baidu.com") //我们可以通过原生的 en
阅读全文
摘要:async function imageToData64(Url) { //传任意一图片地址 return new Promise((resolve, reject) => { let image = new Image(); image.src = itemUrl; image.crossOrig
阅读全文
摘要://防止连点 const canHamdle = useRef(true); function onHandleSubmit() { if (!canHamdle.current) { return } else { fun something(); canHamdle.current = fals
阅读全文
摘要:dayjs('2021-10-19').diff('2021-11-18', 'day'))
阅读全文
摘要:import { createElement, useEffect, useState } from 'rax'; import View from 'rax-view'; import classnames from 'classnames'; import { isValidNumber } f
阅读全文
摘要:淘宝参考:http://h5.alibaba-inc.com/api/WindVane-API.html 支付宝参考:https://smallfish.antfin-inc.com/alipayjsapi/ap.chooseImage.html#option-%E5%8F%82%E6%95%B0%
阅读全文
摘要:处理逻辑,经常需要在dom重现使用时回掉函数(重新请求数据,重新定义状态等),以下是工作中常用的一个重新回掉函数的定义: import { useEffect } from "react"; export default function useResume(fn: any, deps: Array
阅读全文
摘要:function ViewMore({ hasMore, request, cursor, list }) { function handleOnAppear() { if (!hasMore) { return; } request(cursor); } return ( <View classN
阅读全文
摘要:工作中从后端取到的数据是一个[proxy]值类型时,我们要获取数据时,可用 JSON.parse(JSON.stringify(data))。 来获取其中的值(解封法)
阅读全文
摘要:一行代码搞定: new Date().getFullYear() + (new Date().getMonth() + 1).toString().padStart(2, "0") + new Date().getDate().toString().padStart(2, "0")注意点:获取当前月
阅读全文