// 封装好
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)
}
网友评论