How to realize vue Anti-shaking
This article mainly introduces the relevant knowledge of "how to achieve vue anti-shaking". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to achieve vue anti-shaking" can help you solve the problem.
1. First, create a new debounce.js code 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 debounce2. Introduce debounce into the vue file that needs anti-shake, as follows; this is the anti-shake of the 500ms of an input box
Import debounce from ".. / utils/debounce"
Export default {
Name: "alarm"
Data () {
Return {
Input:''
}
}
Methods: {
ChangeSeletc:debounce (function () {
Console.log (this.input)
}, 500)
}
}
This is the end of the content about "how to achieve vue anti-shaking". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.