vue-objectex
v1.0.4
Published
An advanced object for vue, can be used as an enum.
Downloads
12
Readme
Getting started
This package is an advanced object for vue, can be used as an enum.
- Install the package:
npm install --save vue-objectex
Usage
Examples
- Use example:
import { ObjectEx } from 'vue-objectex'
const objEx = new ObjectEx([
// Basic options, define enums
{
key: "item1",
value: 1,
desc: "Item 1"
}, {
key: "item2",
value: 2,
desc: "Item 2"
}, {
key: "item3",
value: 3,
desc: "Item 3"
}], {
// Extend funcs
getDesc(value) {
let enumOption = this.valueOf(value);
return !!enumOption ? enumOption.desc : "";
},
...
}, {
// Extend props
basicOptions: {
get() {
return this.getOptions();
}
}
});
- Extend example:
import { ObjectEx } from 'vue-objectex'
class UserManager extends ObjectEx {
constructor(options, funcExtensions, defineProps) {
let innerOptions = [];
if (Object.typeOf(options) === "array") {
Object.copy(innerOptions, options);
}
let innerFuncExtensions = {
isInRole(roleName) {
...
}
};
if (typeof(funcExtensions) === "object") {
innerFuncExtensions = {...innerFuncExtensions, ...funcExtensions};
}
let innerDefineProps = {
isAdmin: {
get() {
return ...;
}
},
...
};
if (Object.typeOf(defineProps) === "object") {
innerDefineProps = {...innerDefineProps, ...defineProps};
}
super(innerOptions, innerFuncExtensions, innerDefineProps);
}
}
Change Log
CHANGELOG.md