uniapp开发使用前需要先安装lodash
html
<div class="submit" @click="gopay">
提交
</div>
js
import _ from 'lodash'
// 节流
gopay: _.throttle(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 => {
})
}, 1000),
使用变量全局控制节流时间
import configs from '@/config/config.js'
import _ from 'lodash'
gopay: _.throttle(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),