zoukankan      html  css  js  c++  java
  • vue函数节流防抖

    //js
    /**
     * 函数节流
     * @param func
     * @param wait
     * @returns {function(...[*]=)}
     */
    export const throttle = (func, wait = 1500) => {
            let timeout;
            return function() {
                let context = this;
                let args = arguments;
                if (!timeout) {
                    timeout = setTimeout(() => {
                        timeout = null;
                        func.apply(context, args)
                    }, wait)
                }
            }
        }
        /**
         * 函数防抖
         * @param func
         * @param wait
         * @returns {function(...[*]=)}
         */
    export const debounce = (func, wait = 1500) => {
        let timeout;
        return function() {
            let context = this;
            let args = arguments;
            if (timeout) clearTimeout(timeout);
            timeout = setTimeout(() => {
                func.apply(context, args)
            }, wait);
        }
    }
    //vue
    import { debounce, throttle } from "./tool";
    methods: {
         tabbtn: debounce(function (index) {
         }, 1000),
    }
  • 相关阅读:
    woj 1574
    UESTC 594 我要长高 dp单调队列
    HDU 3401 Trade dp 单调队列优化
    HDU 2844 Coins 多重背包
    2-1
    1-2
    1-1
    12-1
    9-1
    14-8
  • 原文地址:https://www.cnblogs.com/minghan/p/14601055.html
Copyright © 2011-2022 走看看