其他分享
首页 > 其他分享> > vue中防抖函数的写法以及用法

vue中防抖函数的写法以及用法

作者:互联网

1.准备好防抖函数

function debounce(func, wait) {       let timeout;       return function (...args) {         if (timeout) clearTimeout(timeout);           let isTime = !timeout;           timeout = setTimeout(function () {             timeout = null;           }, wait);           if (isTime) func.apply(this, args);         };     } 2.html节点 <input type="button" @click="toDoSth" />   3.methods中调用 methods: {     toDoSth: debounce(       function () {         this.log();       },       500,       true     ),     log() {       console.log(12313);     }   },

标签:function,vue,log,中防抖,args,let,timeout,写法,methods
来源: https://www.cnblogs.com/a8497336/p/16495831.html