赞
踩
1.在utils文件中新建一个loadMore.ts文件。
import type { Directive, App } from 'vue'; const debounce = function (func: any, delay: any) { let timer: any = null return function () { if (timer) clearTimeout(timer) timer = null let self = this let args = arguments timer = setTimeout(() => { func.apply(self, args) }, delay) } } const loadMore: Directive = { mounted (el: any, binding: any, vnode: any) { const { expand } = binding.modifiers // 使用更丰富的功能,支持父组件的指令作用在指定的子组件上 if (expand) { /** * target 目标DOM节点的类名 * distance 减少触发加载的距离阈值,单位为px * func 触发的方法 * delay 防抖时延,单位为ms * load-more-disabled 是否禁用无限加载 */ let { target, distance = 0, func, delay = 200 } = binding.value if (typeof target !== 'string') return let targetEl = el.querySelector(target) if (!targetEl) {
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。