kbdsbx / vuex-declaration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vuex Declaration

Declare state like props, make state inject to vuex dynamically when component created.

Usage

npm i vuex-declaration
import vuecDeclaration from 'vuex-declaration'
import Vue from 'vue'
Vue.use( vuexDeclaration );
Vue.component( 'self-component', {
    data () { ... },
    props : [ ... ],
    created () { ... },

    // Declare states
    state : [ 'state-a', 'state-b' ],
} )
export default {
    // Declare state with module.
    state : {
        'state-a' : {
            module : 'module-a',
        }
    }
}

Apis

setStoreModule

Append states to existing modules.

import { setStoreModule } from 'vuex-declaration'

setStoreModule( this.$store, [ 'state-a', 'state-b' ] )

resetStoreModule

Unreginster all modules from $store and then reset these.

import { resetStoreModule } from 'vuex-declaration'

resetStoreModule( this.$store, [ 'state-a', 'state-b' ] )

About


Languages

Language:JavaScript 54.6%Language:Vue 45.4%