1、html模板
<template>
<div class="container">
<el-input v-model="iptDate"></el-input>
</div>
</template>
2、data里声明数据
iptDate:'',
laterTime: null,
3、watch方法监听数据变动,调用防抖方法
watch:{
iptDate(newValue,oldValue) {
if(newValue) {
this.listenThings()
}
}
},
4、防抖方法
listenThings() {
if(this.laterTime) {
clearTimeout(this.laterTime)
}
this.laterTime = setTimeout(() => {
console.log('延迟时间生效了');
},800)
}