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

vue3-data-container

v1.0.0

Published

vue components that provide data request

Readme

vue3 data container

  • 包装了数据请求的 vue 容器组件
  • 灵活控制前端数据请求的三大状态:pending, finished, error
  • 让数据请求组件化
  • 可扩展其支持 fetch, axios 等任意请求库

Install

npm i vue3-data-container

// or

yarn add vue3-data-container

Usage

本例以接入 axios 请求库为例

// main.js
import axios from 'axios'
import dataContainer from 'vue3-data-container'

// const app = createApp(App);

app.component('axios-data-container', dataContainer.create({
  // 比较抽象的业务接口请求封装
  async serviceHandler(method, url, params) {
    let error, data;
    try {
      const res = await axios[method](url, {/*...*/})
      const {
        code,
        msg,
        ...rest
      } = res
      if (code === 0) {
        data = {
          msg,
          ...rest
        }
      } else {
        error = msg
      }
    } catch(e) {
      error = e.message
    }

    // 此处务必返回 error 和 data
    return {
      error,
      data
    }
  }
}))

在 SFC 中使用上面定义的 axios-data-container 组件

内置的 default, data, loading, error 四个 slot 可用来自定义数据渲染区域

<template>
  <axios-data-container
    url="http://localhost:3000/api/test"
    params="{}">
    <tempalte #data="{ res }">
      <div v-for="item of res.records">
        {{ item }}
      </div>
    </template>
    <template #loading>loading</template>
    <template #error>error</tempalte>
  </axios-data-container>
</template>

创建容器组件的静态方法:create

container.create ({ serviceHandler, headers }) => ContainerComponent

容器组件参数

| 名称 | 类型 | 默认值 | 说明 | | ---- | ---- | ---- | ---- | | method | string | POST | 请求类型 | | url | string | - | 请求地址 | | params | object | - | 请求参数 | | options | object | - | 其他参数 | | cached | boolean | false | 是否缓存结果 | | noCached | boolean | true | 不缓存结果 |

如何接入 fetch-functions-api

项目中需自己安装 @all-in-js/fetch-functions-api

fetch-functions-api 使用参考:ffa

// main.js
import fetchFunctionsContainer from 'vue3-data-container/fetch-functions-api'

// const app = createApp(/* App */);

app.component('fetch-container', fetchFunctionsContainer({
  successCode: 1000,
  url: 'api/functions'
}))