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

@bams-app/data-dict

v0.2.1

Published

## 简介

Readme

@bams-app/data-dict

简介

用于数据字典管理,支持 Vue 3 Composition API 和传统 Options API。

安装

npm install @bams-app/data-dict

使用

1. 全局安装

import { createApp } from "vue";
import DataDict from "@bams-app/data-dict";

const app = createApp(App);
app.use(DataDict, {
  // 全局配置
  onCreated: dict => {
    console.log("Dict created:", dict);
  },
  onReady: dict => {
    console.log("Dict ready:", dict);
  },
});
app.mount("#app");

2. Options API 方式

export default {
  dicts: {
    userStatus: {
      url: "/api/dict/userStatus",
    },
    gender: {
      data: [
        { value: "M", label: "男" },
        { value: "F", label: "女" },
      ],
    },
  },
  methods: {
    onDictReady(dict) {
      // 字典加载完成后调用
      console.log(dict);
      const userStatus = dict.get("userStatus");
    },
  },
};

3. Composition API 方式

import { useDataDict } from "@bams-app/data-dict";

export default {
  setup() {
    const { dict, isReady, getDictOptions } = useDataDict({
      dicts: {
        userStatus: {
          url: "/api/dict/userStatus",
        },
      },
      onReady: dict => {
        console.log("Dict is ready:", dict);
      },
    });

    return { dict, isReady, getDictOptions };
  },
};

4. 独立使用

import { DataDict } from "@bams-app/data-dict";

const dict = new DataDict();
dict.init({
  userStatus: {
    url: "/api/dict/userStatus",
  },
});

// 获取字典项
const userStatus = dict.get("userStatus");

API 文档

useDataDict(options)

参数

  • dicts - 字典配置
  • onReady - 字典加载完成回调
  • provide - 是否提供给子组件(默认 true)

返回值

  • dict - 字典实例
  • isReady - 字典是否准备就绪
  • error - 错误信息
  • parentDict - 父组件字典
  • initDict - 初始化字典
  • destroyDict - 销毁字典
  • getDictItem - 获取字典项
  • getDictOptions - 获取字典选项
  • refreshDict - 刷新字典

DataDict 实例方法

  • init(dicts) - 初始化字典
  • get(key) - 获取字典项
  • getOptions(key) - 获取字典选项
  • refresh(key) - 刷新字典
  • destroy() - 销毁字典

示例

在模板中使用

<template>
  <select>
    <option v-for="item in userStatusOptions" :key="item.value" :value="item.value">
      {{ item.label }}
    </option>
  </select>
</template>

<script setup>
  import { useDataDict } from "@bams-app/data-dict";
  import { computed } from "vue";

  const { isReady, getDictOptions } = useDataDict({
    dicts: {
      userStatus: {
        url: "/api/dict/userStatus",
      },
    },
  });

  const userStatusOptions = computed(() => {
    if (isReady.value) {
      return getDictOptions("userStatus");
    }
    return [];
  });
</script>

配置说明

字典配置

{
  userStatus: {
    url: '/api/dict/userStatus', // 接口地址
    method: 'get', // 请求方法
    params: {}, // 请求参数
    data: [], // 静态数据
    labelField: 'label', // 显示字段
    valueField: 'value', // 值字段
    childrenField: 'children' // 子节点字段
  }
}

注意事项

  1. 确保接口返回的数据格式符合要求
  2. 在字典未准备就绪时避免调用相关方法
  3. 使用 Composition API 时建议配合 computed 使用
  4. 不需要时记得销毁字典实例