先看定义
https://lodash.com/docs#debounce
https://lodash.com/docs#throttle
一开始我用
throttleSave: _.throttle(function () { this.save() }, 1500),
去防止多次点击,但是总会调用两次
后来改成
目的达到了,但是不理想,一直点击总是在停止点击后再执行
最后看了文档改成
throttleSave: _.throttle(function () { this.save() }, 1500, { trailing: false }),这样效果最好,
[options.leading=true] (boolean): Specify invoking on the leading edge of the timeout.
[options.trailing=true] (boolean): Specify invoking on the trailing edge of the timeout.