本文主要是介绍vue中防抖使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
防抖是在事件被触发n秒后再执行回调函数,如果在这n秒内又被触发,则重新计时。
<template><div> <input v-model="value" @keyup="handleChange" /></div>
</template>
<script>export default {name: "",data() {value:"",times: null},method: {handleChange() {if(this.times){clearTimeout(this.times)}this.times = setTimeout(() => {//调用接口}, 500);}},beforeDestroy(){clearTimeout(this.times);},}
</script>
这篇关于vue中防抖使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!