Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

alex-oleshkevich/vue-config

Repository files navigation

vue-configuration

A static config plugin.

Installation

Add package

yarn add vue-configuration

# or via npm:
npm i vue-configuration

Install plugin

import Vue from 'vue';
import VueConfig from 'vue-configuration';
import appConfig from './config.js';

// pass config object to the plugin
Vue.use(VueConfig, {
    config: appConfig
});

Usage

Access config values in any part of app using simple API:

this.$config.get('node');

Use dot-notation for keys:

this.$config.get('node.child.leaf');

Default values if value not set:

this.$config.get('node.child.leaf.empty', 'default');

Replace config:

this.$config.replace({ new: 'data' });

Test if path exists:

// obj = { a: 1 }
this.$config.has('a.b.c'); // false
this.$config.has('a'); // true

Get config object:

this.$config.all();

Example

config.js

export default {
    facebook: {
        apiToken: 'abc',
        clientSecret: 'topsecret'
    },
    allowRegistration: true
};

Get node:

this.$config.get('facebook');
// { apiToken: 'abc', clientSecret: 'topsecret' }

Read Facebook's API token in component:

this.$config.get('facebook.apiToken');
// 'abc'

Test if registration is open:

this.$config.get('allowRegistration');
// true

Test if login is available:

this.$config.get('allowLogin', false);
// oops, not defined! return "false" as default

About

A static config plugin.

Resources

License

Stars

Watchers

Forks

Packages

No packages published