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

@mvmoo/optionsapi

v0.0.2

Published

对vue2||uni-app使用 options API 的通用函数封装

Downloads

5

Readme

分页

<template>
  <view>
    <!-- 查询框 -->
    <input v-model="keyword" @confirm="handleSearch" placeholder="请输入关键词" />

    <!-- 表格列表 -->
    <view v-if="paginated.loading">加载中...</view>
    <view v-else>
      <view v-for="item in paginated.data" :key="item.id">
        {{ item.name }}
      </view>
    </view>

    <!-- 分页器 -->
    <view>
      <button @click="handlePrev" :disabled="paginated.pagination.page === 1">上一页</button>
      <text>第 {{ paginated.pagination.page }} 页</text>
      <button @click="handleNext">下一页</button>
    </view>
  </view>
</template>

<script>
import { createPaginated } from '@mvmoo/optionsapi'
import { getUserList as api } from '@/api/user' // 示例接口

export default {
  data: () => ({
    finished: false,
    keyword: '',
    paginated: createPaginated(api, { keyword: '' }, {
      pageKey: 'page',
      limitKey: 'limit',
      extractList: res => res.data.rows,
      extractTotal: res => res.data.total,
      defaultPagination: { page: 1, limit: 10 },
      transformData: (rows, res, query) => {} // 自定义格式化数据
    }, 'concat(如果传递末尾参数代表开启数据叠加:适配移动端触底加载, 自行通过count判断是否继续触底)')
  }),

  created() {
    // ✅ 初始化加载
    this.paginated.reload({ keyword: '如果这里传递了参数 createPaginated第二个参数可设置为null' }, 1)
  },

  methods: {
    // 🔍 执行查询
    handleSearch() {
      this.paginated.onSearch({ keyword: this.keyword })
    },

    // 🔁 翻页(下一页)
    handleNext() {
      const { page, limit, total, count } = this.paginated.pagination
      const maxPage = Math.ceil(total / limit)
      if (page < maxPage) {
        this.paginated.onChangePage(page + 1, limit)
      }
    },

    // 🔁 翻页(上一页)
    handlePrev() {
      const { page, limit, count } = this.paginated.pagination
      if (page > 1) {
        this.paginated.onChangePage(page - 1, limit)
      }
    },

    // 🔄 手动刷新
    handleReload() {
      this.paginated.reload({}, 1)
    }
  }

  /* 示例uniapp触底加载 */
  onReachBottom () {
    if (this.finished) return
    const { page, limit, total, count } = this.paginated.pagination
    this.paginated.onChangePage(page + 1, limit)
    this.finished = count < limit
  },
}
</script>