随笔分类 - js
摘要:小程序需要模拟双击事件,如果一个元素既绑定了单击事件,又绑定了模拟的双击事件,如何区分两个事件何时触发呢? 1. 设计一个点击事件分发函数 如果用户两次点击的时间间隔不大于300ms,认为发生了双击行为。 当用户点击一次后,等400ms,如果用户没有发生第二次点击,则认为是单击 export fun
阅读全文
摘要:判断类型见:https://www.cnblogs.com/zhoulixue/p/17187385.html // 深拷贝 export const deepclone = (source: any) => { if (getType(source) 'Object') { return Obje
阅读全文
摘要:获取类型 // 获取数据类型 export const getType = (o: any) => Object.prototype.toString.call(o).slice(8, -1); export const isObject = (o: any) => getType(o) 'Obje
阅读全文
摘要:// 类 class Greeter { greeting: string; constructor(message: string) { this.greeting = message; } greet() { return `Hello, ${this.greeting}`; } } const
阅读全文
摘要:interface LabeledValue { label?: string; // 可选属性 } function printLabel(labelObj: LabeledValue) { console.log(labelObj.label); } const myObj = { size:
阅读全文
摘要:const iaMale: boolean = true; // 布尔值 const myAge: number = 18; // 数字 const myName: string = 'tom'; // 字符串 const scores: number[] = [100, 90, 80]; // 数
阅读全文
摘要:类型变量,一个组件可以支持多种数据类型的数据 基础用法 function identity<T>(arg: T): T { return arg; } const output = identity('myString'); console.log(output); 泛型变量 function id
阅读全文
摘要:get const http = require('http'); const url = require('url'); const host = 'http://localhost:3000'; http.createServer(function (req, res) { const { se
阅读全文
摘要:index.ejs <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" c
阅读全文
摘要:1. 工具函数 module/file.js 读取文件数据 const fs = require('fs'); const readFile = (path) => new Promise((resolve) => { fs.readFile(path, (err, data) => { resol
阅读全文
摘要:写数据流 const fs = require('fs'); let str = ''; for (let i = 0; i < 1e4; i++) { str += `写入数据${i}\n`; } const writeStream = fs.createWriteStream('./data/o
阅读全文
摘要:创建一个upload文件夹 const fs = require('fs'); // 创建文件夹 const mkdir = (path) => new Promise((resolve) => { fs.mkdir(path, (err) => { resolve({ err }); }); })
阅读全文
摘要:检测是文件还是目录 const fs = require('fs'); fs.stat('./html', (err, stat) => { if (err) { console.log(err); return; } const isDirectory = stat.isDirectory();
阅读全文
摘要:new URL(input, [base]) base验证input的origin是否符合预期 let myUrl = new URL('test/index.html', 'https://example.com'); // https://example.com/test/index.html
阅读全文
摘要:1. 组件注册懒加载 (1)全局注册 Vue.component('AsyncComponent', ()=> import('./AsyncComponent.vue')) (2)局部注册 new Vue({ components: { AsyncComponent: () => import('
阅读全文
摘要:index.js async function getComponent () { const { default: _ } = await import(/*webpackChunkName: "lodash"*/'lodash') await import(/* webpackChunkName
阅读全文
摘要:使用 import() 语法实现动态导入 project webpack-demo |- package.json |- webpack.common.js |- webpack.dev.js |- webpack.prod.js |- /dist |- /src |- index.js |- /n
阅读全文
摘要:入口起点分离: 使用 entry 手动的分离代码。(配置多,并且有一些隐患,不建议使用) project webpack-demo |- package.json |- webpack.common.js|- webpack.prod.js|- webpack.dev.js |- /dist |-
阅读全文
摘要:常用方式:放到</body>之前,解决js运行时找不到dom的问题。 页面渲染过程(HTML parser) <html> <head> <link rel="stylesheet" type="text/css" href="/style.css"> <script type="text/java
阅读全文
摘要:function debounce(func, waite) { let timerId = null return function(...args) { if (timerId) { clearTimeout(timerId) } timerId = setTimeout(() => { func(...args) }, wai...
阅读全文