防抖是在事件被触发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>