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 🙏

© 2024 – Pkg Stats / Ryan Hefner

enum-vue

v1.0.6

Published

前端枚举工具

Downloads

3

Readme

enum-vue

前端常量 枚举工具

项目基于 https://github.com/1024-lab/vue-enum.git

一、安装及初始化

安装

npm i enum-vue

初始化(定义枚举对象)

import Enum from 'enum-vue'
import Vue from "vue"

const enumInfo = {
  // 订单状态
  ORDER_STATUS: {
    WAIT_BUYER_PAY: {
      value: 'WAIT_BUYER_PAY',
      desc: '等待买家付款'
    },
    WAIT_SELLER_SEND_GOODS: {
      value: 'WAIT_SELLER_SEND_GOODS',
      desc: '等待卖家发货,即:买家已付款'
    },
    WAIT_BUYER_CONFIRM_GOODS: {
      value: 'WAIT_BUYER_CONFIRM_GOODS',
      desc: '等待买家确认收货,即:卖家已发货'
    },
    TRADE_FINISHED: {
      value: 'TRADE_FINISHED',
      desc: '交易成功'
    }
  }
}

Vue.use(Enum, { enumInfo })

二、使用

获取所有枚举Key列表

this.$enum.key

// result
{ "ORDER_STATUS": "ORDER_STATUS" }

根据枚举值获取描述(表格列表渲染中枚举值转换描述)

row.orderStatus = ‘TRADE_FINISHED’
this.$enum.getDescByValue('ORDER_STATUS', row.orderStatus)
// 或
this.$enum.getDescByValue(this.$enum.key.ORDER_STATUS, row.orderStatus)

// result
交易成功

获取键值对数组(下拉列表渲染中根据类型获取键值对)

this.$enum.getValueDescList(this.$enum.key.ORDER_STATUS)

// result
[{
  value: 'WAIT_BUYER_PAY',
  desc: '等待买家付款'
}, {
  value: 'WAIT_SELLER_SEND_GOODS',
  desc: '等待卖家发货,即:买家已付款'
}, {
  value: 'WAIT_BUYER_CONFIRM_GOODS',
  desc: '等待买家确认收货,即:卖家已发货'
}, {
  value: 'TRADE_FINISHED',
  desc: '交易成功'
}]
<select>
  <option
    v-for="(item,index) in $enum.getValueDescList(this.$enum.key.ORDER_STATUS)"
    :value="item.value"
    :key="index"
  >{{ item.desc }}
  </option>
</select>

根据枚举名称获取对应值与描述键值对

this.$enum.getValueDesc(this.$enum.key.ORDER_STATUS)

// result
{
  WAIT_BUYER_PAY: '等待买家付款',
  WAIT_SELLER_SEND_GOODS: '等待卖家发货,即:买家已付款',
  WAIT_BUYER_CONFIRM_GOODS: '等待买家确认收货,即:卖家已发货',
  TRADE_FINISHED: '交易成功'
}