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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dhlx/virtual-scrolling

v0.0.2

Published

vue3 虚拟滚动

Downloads

6

Readme

VirtualScrolling 组件

一个强大的用于 Vue 应用程序的虚拟滚动组件。

目录

安装

使用 npm 安装这个包:

npm install @dhlx/virtual-scrolling

使用方法

以下是在你的 Vue 项目中使用VirtualScrolling组件的示例:

<script setup>
import VirtualScrolling from "@dhlx/virtual-scrolling";
import { reactive, useTemplateRef } from "vue";
import data from "../data.json";
import "@dhlx/virtual-scrolling/dist/style.css";
const Item = VirtualScrolling.Item;

const _data = reactive(data);

const listRef = useTemplateRef("list");

const setHeight = (index, e) => {
  if (listRef.value) {
    listRef.value.resetListHeight(index, e);
  }
};
</script>

<template>
  <VirtualScrolling :value="_data" :auto-height="true" ref="list" :default-item-height="48" height="500px">
    <template #item="{data, index, height}">
      <Item @ready="e => setHeight(index,e)">
        <div class="item">
          {{ index }}:{{ data.text }}
        </div>
      </Item>
    </template>
  </VirtualScrolling>
</template>

<style scoped>
.item {
  background: #cccccc;
}
</style>

在上述代码中,首先从@dhlx/virtual-scrolling引入VirtualScrolling组件和Item子组件,通过reactive将数据转为响应式数据,使用useTemplateRef获取模板引用。在模板中,使用VirtualScrolling组件并传入相应的属性和ref,通过插槽定义Item的结构,并在Item组件上监听ready事件,触发setHeight方法来处理高度设置,通过模板引用调用resetListHeight方法更新特定索引处的项目高度。

属性

  • value
    • 类型:数组。
    • 默认值:一个返回空数组的函数。用于提供要在虚拟滚动列表中显示的数据数组。
  • defaultHeight
    • 类型:数字。
    • 默认值:50。当autoHeight为 false 时使用的默认高度。
  • autoHeight
    • 类型:布尔值。
    • 默认值:true。表示是否自动计算项目高度。
  • maxShowNumber
    • 类型:数字。
    • 默认值:15。设定最大显示的项目数量。
  • default-item-height:用于设置每个项目的默认高度。

事件

  • ready:由Item组件发出,当它准备好时。将项目的高度作为参数传递给父组件的方法。

暴露的方法

  • resetListHeight(index, { clientHeight }):用于更新列表中特定索引处的项目高度为给定的clientHeight

贡献

欢迎贡献!请 fork 仓库并提交 pull request。

许可证

这个项目使用 MIT 许可证