vue中的防抖与节流,minxin

参考文档:

https://www.jb51.net/article/161713.htm
 
或者
 
// 防抖
const debounce = (func, wait, immediate) => {
            let timeOut;
            return function () {
                const context = this;
                const args = arguments;
                if (timeOut) {
                    clearTimeout(timeOut);
                }
                if (immediate) {
                    let callNow = !timeOut;
                    timeOut = setTimeout(() => {
                        timeOut = null;
                    }, wait || 500)
                    if (callNow) {
                        func.apply(context, args);
                    }
                } else {
                    timeOut = setTimeout(() => {
                        func.apply(context, args);
                    }, wait || 500);
                }

            }
        }
// 组件中调用
<el-input type='text' @input="test($event)">

// 引入防抖
import {Debounce} from './utils';


export default {

    methods:{

        test(e){

            Debounce(()=>{
               console.log(e);
            },1000)
        }
    

    }
}            

 Minxin参考地址:https://blog.csdn.net/qq_38128179/article/details/107817436

posted @ 2021-11-13 11:52  面包_girl  阅读(85)  评论(0编辑  收藏  举报
/* 鼠标点击文字特效 */