npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhenzichao/vue2-infinite-scroll

v1.0.0

Published

A lightweight infinite scroll component plugin for Vue 2 - page scroll load more data with IntersectionObserver

Downloads

446

Readme

@zhenzichao/vue2-infinite-scroll

基于 IntersectionObserver 的 Vue2 无限滚动组件,轻松实现列表无限加载

npm version License: MIT

📖 详细使用文档 (必看)

特性

  • IntersectionObserver 驱动 — 使用现代浏览器 API 检测滚动触底,无需手动计算滚动位置
  • 节流控制 — 内置加载节流机制,防止短时间内重复触发请求
  • 自动填充检测 — 一页数据不足以填满视口时,自动触发下一次加载
  • 空状态自动判断 — 根据数据自动判断空状态,配合 loadMore 首次加载确定是否真实为空
  • 加载完成提示 — 数据全部加载完毕后显示提示文字,支持自定义
  • 手动控制 — 提供 finish()reset() 方法,可手动控制加载状态
  • 零依赖 — 不依赖任何第三方库,轻量高效

安装

npm install @zhenzichao/vue2-infinite-scroll

yarn add @zhenzichao/vue2-infinite-scroll

pnpm add @zhenzichao/vue2-infinite-scroll

快速开始

注册插件

import Vue from 'vue'
import InfiniteScroll from '@zhenzichao/vue2-infinite-scroll'

Vue.use(InfiniteScroll)

基础使用

<template>
  <ZcInfiniteScroll :load-more="loadMore">
    <div v-for="item in list" :key="item.id">{{ item.name }}</div>
  </ZcInfiniteScroll>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      page: 1
    }
  },
  methods: {
    async loadMore() {
      const res = await fetch(`/api/list?page=${this.page}`)
      const data = res.data
      this.list.push(...data)
      this.page++
      return data.length === 0 // 返回 true 表示已加载完毕
    }
  }
}
</script>

配置选项

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | loadMore | Function | — | 必填,触底时调用的加载函数,应返回 Promise,resolve 为 true 表示加载完毕 | | throttle | Number | 300 | 两次加载之间的最小间隔时间(ms) | | loadingText | String | '加载中...' | 加载状态提示文字 | | finishedText | String | '--到底了--' | 加载完毕提示文字 |

插槽

| 插槽名 | 说明 | |--------|------| | default | 列表内容区域,有数据时渲染 | | empty | 空状态内容,加载完毕后数据仍为空时渲染 | | loading | 自定义加载提示,默认显示 loadingText | | finished | 自定义加载完毕提示,默认显示 finishedText |

方法(通过 ref 调用)

finish()

手动标记为加载完毕状态。

<template>
  <ZcInfiniteScroll ref="scroll" :load-more="loadMore">
    ...
  </ZcInfiniteScroll>
</template>

<script>
export default {
  methods: {
    stopLoading() {
      this.$refs.scroll.finish()
    }
  }
}
</script>

reset()

重置组件状态(清除 finished 和 loading 标记,重新初始化 Observer),适用于刷新列表场景。

this.$refs.scroll.reset()

使用场景

场景 1:分页列表加载

<template>
  <ZcInfiniteScroll :load-more="loadMore">
    <div v-for="item in list" :key="item.id">{{ item.name }}</div>
  </ZcInfiniteScroll>
</template>

<script>
export default {
  data() {
    return { list: [], page: 1, loading: false }
  },
  methods: {
    async loadMore() {
      this.loading = true
      const data = await api.getList(this.page++)
      this.list.push(...data)
      this.loading = false
      return data.length < 10 // 每页10条,不足10条说明到底了
    }
  }
}
</script>

场景 2:自定义空状态与加载提示

<template>
  <ZcInfiniteScroll :load-more="loadMore">
    <div v-for="item in list" :key="item.id">{{ item.name }}</div>
    <template #empty>
      <div class="empty-state">暂无数据</div>
    </template>
    <template #loading>
      <div class="custom-loading">正在加载更多...</div>
    </template>
    <template #finished>
      <div class="custom-finished">没有更多内容了</div>
    </template>
  </ZcInfiniteScroll>
</template>

场景 3:刷新重置列表

// 清空数据后重置滚动组件
this.list = []
this.$refs.scroll.reset()

License

MIT