1. template
<el-input placeholder="请输入搜索内容" v-model="params.search">
2.定义一个节流匿名函数
const delay = (function () {
let timer = 0
return function (callback, ms) {
clearTimeout(timer)
timer = setTimeout(callback, ms)
}
})();
3. data对象
data() {
return {
params: {
page: '1',
search: ''
}
}
},
4. watch 方法
watch: {
"params.search"() {
delay(() => {
this.fetchData();
}, 1000);
}
}