my view:
ns-input#filterName(type="text", v-model="filterName", @keyup="searchTimeOut()")
在我的 vue 代码中:
getUsers() {
.
.
.
API.users.index(params).then(blabla);
.
.
.
},
searchTimeOut() {
let timeout = null;
clearTimeout(timeout);
// Make a new timeout set to go off in 800ms
timeout = setTimeout(() => {
this.getUsers();
console.log("hi")
}, 800);
},
我要打电话getUsers()
仅在我停止打字 800 毫秒后一次。现在,我正在打电话getUsers()
每次我写信的时候。
你掉落this.timer
清除间隔之前的值。改为这样做:
searchTimeOut() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
this.timer = setTimeout(() => {
// your code
}, 800);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)