May 30, 2021 Article blog
1. 1. First create a new debounce .js code as follows
2. 2. Introduce debounce in the vue file that requires stabilization, as follows;
const debounce=function(fn, delay){
let timer = null
return function(){
let content = this;
let args = arguments;
if(timer){
clearTimeout(timer)
}
timer = setTimeout(()=>{
fn.apply(content,args)
}, delay)
}
}
export default debounce
<template>
<div class="main">
<el-input v-model="input" @change="changeSeletc" placeholder="请输入内容"></el-input>
</div>
</template>
<script>
import debounce from "../utils/debounce"
export default {
name: "alarm",
data(){
return{
input: ''
}
},
methods:{
changeSeletc:debounce(function () {
console.log(this.input)
},500),
}
}
</script>
<style scoped>
</style>