<el-input type="text" v-model="inp" @input="handleinp" />
//引入 _ lodash
import _ from 'lodash'
data() {
return {
inp: "",
};
},
methods: {
getinput:_.debounce(function () {
// console.log(val);
console.log(this.inp,'=====inp')
}, 2000)
,
handleinp(val) {
this.inp = val;
this.getinput()
},
},
定义防抖的函数getinput ,debounce返回的是一个函数 需要再调用
handleinp中 先获取输入的值, 再使用防抖函数 两秒后获取最终的值