uniapp防抖动(防止多次点击)
工具类function throttle(fn, gapTime) {if (gapTime == null || gapTime == undefined) {gapTime = 1500}let _lastTime = null// 返回新的函数return function () {let _nowTime = + new Date()if (_nowTime - _lastTime >
·
工具类
function throttle(fn, gapTime) {
if (gapTime == null || gapTime == undefined) {
gapTime = 1500
}
let _lastTime = null
// 返回新的函数
return function () {
let _nowTime = + new Date()
if (_nowTime - _lastTime > gapTime || !_lastTime) {
fn.apply(this, arguments) //将this和参数传给原函数
_lastTime = _nowTime
}
}
}
module.exports = {
throttle:throttle,
vuemixin:{
created: function () { console.log(1) }
}
}
在要使用的页面导入工具类(也可在main进行导入)
const util = require('@/utils/commonUtil.js');
import refresh from '@/pagesE/components/linkage-top-navigation/refresh.vue';
import navTab from '@/pagesE/components/linkage-top-navigation/navTab.vue';
import tabBar4 from '@/pagesE/components/linkage-top-navigation/tabBar4.vue';
import clickCircle from '@/pagesE/components/linkage-top-navigation/clickCircle.vue';
import ourLoading from '@/pagesE/components/linkage-top-navigation/our-loading.vue';
export default {
components: {
refresh,
navTab,
clickCircle,
tabBar4,
ourLoading,
},
使用 (util.throttle)
//函数名lower1
lower1: util.throttle(function(e) {
// console.log(`加载${this.currentTab}`) //currentTab表示当前所在页数 根据当前所在页数发起请求并带上page页数
// if(this.flowList)
// console.log(this.flowList.length)
this.count++
this.$emit('reachBottom',this.count)
this.bottomLoadingShow = true
// uni.showLoading({
// title: '加载中',
// mask: true
// })
this.isRequest().then((res) => {
let tempList = this.list
tempList[this.currentTab] = tempList[this.currentTab].concat(res)
// console.log(tempList)
this.list = tempList
this.$forceUpdate() //二维数组,开启强制渲染
})
}, 300),
更多推荐
已为社区贡献4条内容
所有评论(0)