tools.js
export const debounce = (func, delay) => {
let timer = null;
return function () {
const context = this;
const args = arguments;
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(context, args);
}, delay);
}
}
vue组件
// 引入
import { debounce } from '@/utils/tools'
// 使用
methods: {
// 注:这个方法需要手动把当前组件实例传递进来
tagCascaderChange: debounce((val, that) => {
let str = ''
if (that.tagCascaderValues.length) that.tagCascaderValues.forEach(item => str += " " + item[0])
that.$emit('filterTableDataByTags', str.trim())
}, 1000),
}