npm.io
1.0.9 • Published 5 years ago

vuex-convert

Licence
ISC
Version
1.0.9
Deps
0
Size
6 kB
Vulns
0
Weekly
0
Stars
3

Vuex-Convert

Version 1.0.2

Description(简述)

  • Simplify vuex configuration(简化Vuex配置,让你的团队更容易上手)
Install(安装)
$ npm i vuex-convert
Basic usage(基本用法)
  • Create store.js
// /conf/store.js
import Vue from 'vue'
import Vuex from 'vuex'
import VuexConvert from 'vuex-convert'

const STORE = new VuexConvert({
  // State Data(状态变量)
  public:{
    base: 'Hello Vuex'
    // ...other state(其他状态)
  },
  // Modules Data(存放Modules变量)
  modules:{
    user:{
      name: 'Pi'
    }
    // ...other state(其他状态)
  }
})

Vue.use(Vuex)
export default new Vuex.Store(STORE)
  • main.js
import store from './conf/store.js'
  
new Vue({
    store,  // <---- add store
    // Other content
})
Use the demo (使用案例)
// app.vue
export default {
  name: 'App',
  mounted(){
   // get Data
   console.log(this.$store.state.base) // --> "Hello Vuex"
   console.log(this.$store.getters.getBase) // --> "Hello Vuex"
   console.log(this.$store.getters["user/getName"]) // --> "Pi"
    
    // set Data 
    this.$store.dispatch('setBase', 'Update Hello')
    console.log(this.$store.state.base) // --> "Update Hello"
  }
}