工具类

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),
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐