```htmL
<input @blur="blurTWO" v-debounce="searchTWO" v-model="inputAirTWO" />
```
```js
// 模糊查询请求次数频繁,
// 解决思路是
//(1)自定义事件,触发节流
directives: {
debounce: {
inserted: function (el, binding) {
let timer
el.addEventListener('keyup', () => {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
binding.value()
}, 300)
})
}
}
},
//(2)绑定自定义事件调用方法
methods: {
search () {
// 实际要进行的操作 axios.get('')之类的
this.count++
console.log('count is:' + this.count)
}
}
```
网友评论