vue-objectex

1.0.2 • Public • Published

vue-objectex

An advanced object for vue, can be used as an enum.




Getting started

This package is an advanced object for vue, can be used as an enum.

  1. Install the package:
npm install --save vue-objectex



Usage

Examples

  1. 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();
      }
    }
  });

  1. 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




Readme

Keywords

Package Sidebar

Install

npm i vue-objectex

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

11.4 kB

Total Files

6

Last publish

Collaborators

  • louisnikai