Skip to content

Vuex moduled store make simple access from vue component

Notifications You must be signed in to change notification settings

samushi/vuex-global-settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vue plugin that helps to set and get data from vuex store

Installations

npm install samushi-global-settings

Usage

First you need to create vuex module with name global_settings and then to implement store in plugin

import GlobalSettings from 'samushi-global-settings'
import store from './store/index'

Vue.use(GlobalSettings, {store: store});

How to get settings

imagine your state and getters is like this

const state = {
    user: {
        name: "Sami Maxhuni",
        email: "[email protected]"
    },
    banners: {
        show: true
    }
}

const getters = {
    getUserInfo: (state) => state.user,
    getBanners: (state) => state.banners
}

const mutations = {
    setUserInfo: (state, payload) => {
        state.user = Object.assign(state.user, payload);
    }   
}

when you want to get/set any value to the global settings you can do like this way example we do it this in component

mounted(){
    this.$globalSettings().set('setUserInfo.name', "Jusuf Maxhuni");    
},

data(){
    return {
        user_name: this.$globalSettings().get('getUserInfo.name'),
        show_banner: this.$globalSettings().get('getBanners.show')
    }
}

ko-fi

About

Vuex moduled store make simple access from vue component

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published