1.0.5 • Published 3 years ago

mj-debounce-throttle v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

1、下载安装命令

npm install mj-debounce-throttle --save

2、使用方式

2.1、CDN

<div>
    <button onclick="onclickDebounce()">防抖</button>
    <button onclick="onclickThrottle()">节流</button>
</div>

<script src="./node_modules/mj-debounce-throttle/index.js"></script>
<script>
    // 防抖
    onclickDebounce = debounceThrottle.debounce(function () {
        console.log("防抖");
    }, 1000);

    // 节流
    onclickThrottle = debounceThrottle.throttle(function () {
        console.log("节流");
    }, 1000);
</script>

2.2、vue

html

<template>
    <div>
        <el-button type="primary" @click="clickDebounce">防抖</el-button>
        <el-button type="primary" plain @click="clickThrottle">节流</el-button>
    </div>
</template>  

JavaScript

import { debounce, throttle } from "mj-debounce-throttle"; 

export default {
    name: "debounceThrottle",
    data() {
        return {};
    },

    methods: {
        // 防抖
        clickDebounce: debounce(function () {
            console.log("防抖");
        }, 1000),

        // 节流
        clickThrottle: throttle(function () {
            console.log("节流");
        }, 1000),
    },
};