解决办法:加一个防抖函数
export function debounce(fn, delay = 1000) {
let timer = null
return function () {
let args = arguments
if (timer) {
clearTimeout(timer)
timer = null
}
timer = setTimeout(() => {
fn.apply(this, args)// this 指向vue
}, delay)
}
}
使用:
getSearch: debounce(function() {
if (this.inputValue) {
this.$nextTick(() => {
this.getData();
});
this.inputValue == ""
? (this.isShowSearch = false)
: (this.isShowSearch = true);
}
}, 300)