vue-objectex

1.0.4 • 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




Dependencies (0)

    Dev Dependencies (18)

    Package Sidebar

    Install

    npm i vue-objectex

    Weekly Downloads

    4

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    11.8 kB

    Total Files

    6

    Last publish

    Collaborators

    • louisnikai