<template>
<div>
<input type="text" v-model="inputValue" @keyup="handleInput" />
</div>
</template>
<script>
export default {
data() {
return {
inputValue: '',
timer: null
};
},
methods: {
handleInput() {
clearTimeout(this.timer); // 清除上一个定时器
if (this.inputValue.length === 6) {
this.timer = setTimeout(() => {
this.getDiscountPrice();
}, 1000);
}
},
getDiscountPrice() {
// 请求接口的逻辑
console.log('发起请求接口');
// 在这里执行请求接口的逻辑
}
}
};
</script>
input输入定时器防抖
最新推荐文章于 2025-02-09 16:00:32 发布