vue-obj-install

1.1.1 • Public • Published

vue-obj-install

A simple function for install your script/variables/objects/functions/... into global Vue object.

When to use it and when not to:

Use it when you want to use a lot of small function across full application, or want to add for example lodash to all components but you don't want to import it from all components.

Installing

npm install --save vue-obj-install

And in your entry JS file:

import Vue from 'vue';
import install from 'vue-obj-install';

Vue.use(install('first_param', 'second_param'));

Usage:

This wrapper bind your script/variables/objects/functions/... to Vue or this in your defined namespace.

Function gets 2 params install'a.b':

  1. Array[string]|[string] - it is used to give namespace to your object when you pass string it will slice dots and make namespaces according to dots: 'a.b'['a', 'b'] or you can pass created before array with namespaces ['a', 'b']
  2. Your script/variables/objects/functions/... you want to pass to Vue

Examples:

import Vue from 'vue';
import install from 'vue-obj-install';
import lodash from 'lodash';

Vue.use(install('namespace', true)); // example 1
Vue.use(install('a.b', {success: true})); // example 2
Vue.use(install('_', lodash)); // example 3
Vue.use(install(['a', 'c'], {success: true})); // example 4
Vue.use(install(['cl'], console.log)); // example 5
// example 1:
Vue.namespace; // → true
this.namespace; // → true

// example 2:
Vue.a.b; // → {success: true}
this.a.b; // → {success: true}
Vue.a.b.success; // → true
this.a.b.success; // → true

// example 3:
Vue._.now(); // → lodash: Gets the timestamp of the number of milliseconds that have elapsed since the Unix epoch (1 January 1970 00:00:00 UTC).

// example 5:
Vue.cl(true); // → console.log(true)
this.cl(true); // → console.log(true)

Dependents (0)

Package Sidebar

Install

npm i vue-obj-install

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

8.28 kB

Total Files

9

Last publish

Collaborators

  • moques