vue中使用防抖节流
2020-07-09 本文已影响0人
divcssjs
// 封装好
export const debounce = function (handle, duration) {
var durations = duration || 1000
var timer = null
function newHandle () {
var self = this
var args = arguments
clearTimeout(timer)
timer = setTimeout(function () {
handle.apply(self, args)
}, durations)
}
return newHandle
}
组件中使用
import { debounce } from '@/utils/common.js'
methods: {
onSaves: debounce(function onSaves (params) {
console.log(params)
// ...
this.onSave()
}, 1000)
}