vuex-class.js
Use es6 class to write the vuex module, making the code easier to maintain and expand.
Installing
npm install vuex-class.js --save
Document
Example
Vue { super thisstrict = processenvNODE_ENV !== 'production' thisstate = count: 0 // Note: the sub module has no plugins option thisplugins = VuexClass thismodules = two: } // mutations { thisstatecount = count } // getters { return `text:` } // actions { } { super thisstate = isBtn: false thismodules = three: thisnamespaced = true } { thisstateisBtn = !thisstateisBtn } { return thisstateisBtn ? 'true' : 'false' } { super thisstate = {} thisnamespaced = true // ... } const one = const store = one console // 'text:0'console // 'false' onesetCount = 666onemodulestwoconsole // 'text:666'console // 'true' const vm = store vuexClass: one mapVuexClasses: // Join the class in the component one: '' two: 'two' three: 'two/three' console // trueconsole // trueconsole // true
API
-
VuexClass.init()
When the store instance is created, the callconst store =// ...plugins:VuexClass -
VuexClass.bindClass(new Vuex.Store())
When replacing the root state of store, we need to re bind class.const store =// ...state:// ...plugins:VuexClassstorestoreVuexClass -
VuexClass.mapVuexClasses(new VuexClass(), { ... })
The 0.0.6 version is added to find the module and its sub modules, and return the relevant class.const classes = VuexClassconsole // trueconsole // trueconsole // true
License
MIT