uniapp 使用lodash实现防抖效果
使用lodash前需要先安装lodash
html
<div class="submit" @click="gopay">
提交
</div>
js
// 防抖
gopay: _.debounce(
function() {
var that = this;
gopay({
order_id: that.id,
coupon_id: that.coupon_id
}, {
custom: {
auth: true
}
}).then(res => {
if (res.status == 200) {
that.data = res.data
}
}).catch(err => {
})
}, 250, { 'maxWait': 1000 }),
使用变量全局控制节流时间
import configs from '@/config/config.js'
import _ from 'lodash'
gopay: _.debounce(function() {
var that = this;
gopay({
order_id: that.id,
coupon_id: that.coupon_id
}, {
custom: {
auth: true
}
}).then(res => {
if (res.status == 200) {
that.data = res.data
}
}).catch(err => {
})
}, configs.throttleTime, {
'maxWait': 5000,
'leading': true,
'trailing': false
}),