随笔分类 -  JS

摘要:获取后台数据接口,当数据无的时候,可以移除滚动监听 mounted() { // 监听滚动 window.addEventListener("scroll", this.getScroll, true); }, // 瀑布流滚动到底部 getScroll() { // vue 获取元素 const 阅读全文
posted @ 2022-10-12 11:22 DL·Coder 阅读(1456) 评论(0) 推荐(0)
摘要:Object.defineProperty 实现 相当于全局劫持 a ,只要发现 a ,就执行方法(三目运算符); Object.defineProperty(window, 'a', { get: function () { //this指向window.a this.value ? this.v 阅读全文
posted @ 2022-09-01 14:11 DL·Coder 阅读(66) 评论(0) 推荐(0)
摘要:Math.random() 返回一个0~1之间的随机数; Math.floor() 向下取整; Math.ceil() 向上取整; Math.round() 四舍五入; Math.fround() 32位浮点数; 1~10随机数 let num = Math.floor(Math.random() 阅读全文
posted @ 2022-08-30 14:45 DL·Coder 阅读(2097) 评论(0) 推荐(0)
摘要:传送门:https://juejin.cn/post/7136864563172999176 阅读全文
posted @ 2022-08-30 09:49 DL·Coder 阅读(83) 评论(0) 推荐(0)
摘要:使用 element 上传组件,FileReader 解析 JSON 文件。 template 代码 <el-dialog title="提示" :visible.sync="dialogVisible" width="25%"> <el-row class="dialogBox"> <el-upl 阅读全文
posted @ 2022-08-30 09:44 DL·Coder 阅读(1573) 评论(0) 推荐(0)
摘要:多个if判断,看着很乱,使用优雅的代码实现 一个判断 if (fruit == 'apple' ) { console.log('red'); } 俩个判断 if (fruit == 'apple' || fruit == 'strawberry') { console.log('red'); } 阅读全文
posted @ 2022-08-30 08:47 DL·Coder 阅读(1400) 评论(0) 推荐(0)
摘要:核心代码 //全屏 function fullScreen() { // const rootElement = document.documentElement; //若要全屏页面div const element = document.querySelector(".fullScreen_pan 阅读全文
posted @ 2022-08-19 14:39 DL·Coder 阅读(1282) 评论(0) 推荐(0)
摘要:用JS来动态设置CSS样式(设置成行内样式),常见的有以下几种 修改 CSS 属性前,需获取 DOM 元素,获取 DOM 元素方法见:https://www.cnblogs.com 获取dom元素后,直接设置style的属性 某些情况用这个设置 !important值无效 如果属性有'-'号,就写成 阅读全文
posted @ 2022-07-28 19:01 DL·Coder 阅读(1311) 评论(1) 推荐(1)
摘要:1、根据id获取元素 1、根据id获取元素,document.getElementById("id属性的值"),返回值是一个元素对象。 <div class="box" id="oneBox" > <span>测试</span> <span>测试</span> <span>测试</span> </d 阅读全文
posted @ 2022-07-28 18:54 DL·Coder 阅读(310) 评论(0) 推荐(0)
摘要:写的很好的博主 博客园:https://blog.csdn.net/MyFuture_MyDream/article/details/116225441 知乎:https://zhuanlan.zhihu.com/p/112256905 阅读全文
posted @ 2022-07-26 15:31 DL·Coder 阅读(64) 评论(0) 推荐(0)
摘要:监听组合键例子 mounted() { // 绑定监听事件 window.addEventListener("keydown", this.keydown); }, beforeDestroy() { // 移除监听事件 window.removeEventListener('keydown', t 阅读全文
posted @ 2022-07-26 13:36 DL·Coder 阅读(2041) 评论(0) 推荐(0)
摘要:右键事件 @contextmenu.prevent.native="openContextMenu($event, node)" 右键事件 //右键自定义菜单 openContextMenu(ev, node) { this.contextMenuLeft = ev.x - 320; this.co 阅读全文
posted @ 2022-07-15 15:19 DL·Coder 阅读(457) 评论(0) 推荐(0)
摘要:mouseout:鼠标移出事件 contextmenu :弹出右键菜单 mouseover:鼠标移入事件 contextmenu :弹出右键菜单。 mousedown:当用户按下了鼠标还未弹起时触发。 mouseup:当用户释放鼠标按钮时触发。 mouseout:当鼠标移出某个元素上移动时触发。 m 阅读全文
posted @ 2022-07-14 16:23 DL·Coder 阅读(465) 评论(0) 推荐(0)
摘要:第一种 请求api中的response类型必须添加responseType: "blob"(因为response回传不存在blob类型,默认字符串,会导致下载的文件无法解析) // 导出用户登录日志 exportJournalLogin(params) { return http({ url: `J 阅读全文
posted @ 2022-07-13 18:10 DL·Coder 阅读(2406) 评论(0) 推荐(0)
摘要:第一种:JS // 返回唯一标识 getUUID () { return Math.random().toString(36).substr(3, 10); }, 第二种:nanoid 传送门:https://www.npmjs.com/package/uuid 第三种:uuid 传送门:https 阅读全文
posted @ 2022-07-11 10:41 DL·Coder 阅读(2163) 评论(0) 推荐(0)
摘要:由于地区不同,Unicode转换规则不一样,如果不知道代码涉及什么语言,最好使用特定地区的实现方法 大写 toUpperCase toLocaleUpperCase :在基于特定地区实现 const abc = 'abc' abc.toUpperCase() // ABC abc.toLocaleU 阅读全文
posted @ 2022-07-10 15:15 DL·Coder 阅读(182) 评论(0) 推荐(0)
摘要:trim 创建字符串的一个副本,删除前后所有空格字符 const abc = ' abc ' const one = abc.trim() // abc trimLeft 清除字符串开始空格 const abc = ' abc ' const one = abc.trimLeft() // 'abc 阅读全文
posted @ 2022-07-10 11:55 DL·Coder 阅读(206) 评论(0) 推荐(0)
摘要:repeat 复制字符串 const abc = 'abc' abc.repeat(2) // abcabc padStart 复制字符串,如果长度小于制定的长度,在开始位置填充字符,直到满足长度条件。 const abc = 'abc' abc.padStart(5,'.') // ..abc p 阅读全文
posted @ 2022-07-10 11:45 DL·Coder 阅读(1374) 评论(0) 推荐(0)
摘要:startsWith 和 includes 接收第二个参数,从指定的位置向字符串末尾搜索,忽略之前的字符 endsWith 接收第二个参数,表示字符串末尾位置 includes 检查整个字符串 const abc = 'abcdefg' const one = abc.includes('abc') 阅读全文
posted @ 2022-07-09 23:03 DL·Coder 阅读(2382) 评论(0) 推荐(0)
摘要:与 concat() 方法一样,slice()、substr()、substring() 也不会修改调用它们的字符串 slice slice 输入一个参数的时候,默认从当前位置,到最后一位 一个参数,从参数位数起,默认到末尾 二个参数,第一个参数,从第几位开始,第二个参数,截取到第几位 如果第二个参 阅读全文
posted @ 2022-07-09 22:46 DL·Coder 阅读(512) 评论(0) 推荐(0)