封装数据懒加载

63 阅读1分钟
import { useIntersectionObserver } from '@vueuse/core'

import { ref } from 'vue'

export const useLazyData = (fn) => {

  const target = ref(null)

  const { stop } = useIntersectionObserver(

    target,

    ([{ isIntersecting }], observerElement) => {
    
      if (isIntersecting) {
      
        stop()
        
        fn && fn()
        
      }
    }
  )
  return target
}



详情 : vueuse.org/core/useint…