Vue——按钮防抖
按钮多次点击,只执行点击动作完成的一次事件触发
js_2">1.创建utils/once.js文件
javascript">export const Debounce = (fn, t) => {
const delay = t || 500
let timeout
return function () {
const context = this
const args = arguments
if (!timeout) {
timeout = setTimeout(() => {
timeout = null
fn.apply(context, args)
}, delay)
}
}
}
vue_20">2.使用的.vue文件中引用
javascript">import { Debounce } from '../../utils/once'
3.methods方法中使用
javascript"> 方法名: Debounce(function () {
// 方法操作
}, 1000)