<el-input v-model="val" @input="handleInput" />
import { debounce } from '@/utils/index'
export default {
data() {
return {
val: '',
name: '防抖'
}
},
methods: {
handleInput:
debounce(function() {
console.log('调用了', this.name)
}, 500)
}
}
utils/index.js
export function debounce(func, delay) {
let time = null
return function() {
if (time) clearTimeout(time)
time = setTimeout(() => {
func.call(this)
}, delay)
}
}