congming_huose-apk/common/mixins/debounceMixin.js

44 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 防抖混入
* 为Vue组件提供防抖点击功能
*/
import { debounceClick, createDebounceMethod, createDebounceMethods, clearAllDebounceStates } from '../utils/debounce.js';
export default {
methods: {
/**
* 创建防抖点击方法
* @param {string} methodName - 方法名
* @param {number} delay - 防抖延迟时间毫秒默认1000ms
*/
$debounceClick(methodName, delay = 1000) {
createDebounceMethod(this, methodName, delay);
},
/**
* 批量创建防抖方法
* @param {Array} methods - 方法名数组
* @param {number} delay - 防抖延迟时间毫秒默认1000ms
*/
$debounceMethods(methods, delay = 1000) {
createDebounceMethods(this, methods, delay);
},
/**
* 创建防抖函数
* @param {Function} func - 要防抖的函数
* @param {number} delay - 防抖延迟时间毫秒默认1000ms
* @param {string} key - 防抖标识符
* @returns {Function} 防抖后的函数
*/
$createDebounce(func, delay = 1000, key = null) {
return debounceClick(func.bind(this), delay, key);
}
},
beforeDestroy() {
// 组件销毁时清理防抖状态
clearAllDebounceStates();
}
};