1、安装及初始化
1.
npm install vue-emun@1.05 --save // vue2
npm install vue-emun --save // vue3
2.按以下格式定义您的枚举对象
let enumInfo = {
SOURCE_IN_TYPE: {
PURCHASE_IN: {
value: 1,
desc: '采购入库'
},
REFUND_IN: {
value: 2,
desc: '退货入库'
},
CHECK_IN: {
value: 3,
desc: '盘点入库'
},
CONFIRM_IN: {
value: 4,
desc: '取消订单入库'
}
}
}
3.import App from './App.vue'
4. import Enum from 'vue-enum'
5.const app = createApp(App)
6.app.use(Enum,{enumInfo})
二、使用方法
1. this.$enum.getDescByValue('SOURCE_IN_TYPE', 1)) //采购入库
2. let sourceTypeList =this.$enum.getValueDescList('SOURCE_IN_TYPE')
/*
[
{value: 1, desc: "采购入库"},
{value: 2, desc: "退货入库"},
{value: 3, desc: "盘点入库"},
{value: 4, desc: "取消订单入库"}
]
*/
3. this.$enum.getValueDesc('SOURCE_IN_TYPE')
/*
{
1:"采购入库",
2:"退货入库",
3:"盘点入库",
4:"取消订单入库"
}
*/
4. this.$enum.isDependConstant('SOURCE_IN_TYPE','PURCHASE_IN',1) //true