<el-input v-model="pointName" placeholder="请输入内容" />
watch: {
pointName(val) {
this.searchLeft(this, val)
}},
在公共组件中添加你的防抖函数
/**
* @param {Function} func
* @param {number} wait
* @return {*}
*/
export function debounce(func, wait) {
let timeout = ''
return (v) => {
if (timeout) {
clearTimeout(timeout)
}
timeout = setTimeout(() => {
func(v)
}, wait)
}
}
使用前在公共的js中引入 import { debounce } from '@/utils/index'
searchLeft: debounce((vm) => {
const data = vm.leftData.filter(item => item.name.indexOf(vm.pointName) !== -1)
vm.setfilterData(data)
vm.pointName = ''
}, 500),
网友评论