0
点赞
收藏
分享

微信扫一扫

Leetcode33 搜索旋转排序数组

静鸡鸡的JC 2023-08-17 阅读 13

文章目录


代码实现

const debounce = (fn: any, delay: number) => {
    let timer: any = undefined;

    return (item: any) => {
        if (timer) clearTimeout(timer);

        timer = setTimeout(() => fn(item), delay);
    }
};

export default debounce;

单页面引入

// 防抖(单页面引用)
import debounce from '../../../utils/debounce';

全局引入

main.ts

import App from './App.vue';
import debounce from './utils/debounce';

const app = createApp(App);
app.config.globalProperties.$debounce = debounce;

使用

html

<el-slider v-model="sliderValue" size="small" show-input @input="handleScheduleInput" />

单页面使用

let handleScheduleInput = debounce((val: number) => {
    console.log('滑块: ', val);
}, 1000 * 1);

全局使用

// 防抖(全局挂载)
let self = getCurrentInstance()?.appContext.config.globalProperties;

let handleScheduleInput = self?.$debounce((val: number) => {
    console.log('滑块: ', val);
}, 2000 * 1);
举报

相关推荐

0 条评论