Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Last active September 21, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmiller1990/c1ad633d0a6ec98f437e4520e40446ef to your computer and use it in GitHub Desktop.
Save lmiller1990/c1ad633d0a6ec98f437e4520e40446ef to your computer and use it in GitHub Desktop.
<template>
<div id="app">
{{ $store.state.a.name }}
{{ $store.state.a.initData }}
</div>
</template>
<script>
export default {
name: 'app',
}
</script>
<style>
</style>
import Vue from 'vue'
import App from './App.vue'
import store from './store'
new Vue({
el: '#app',
store,
render: h => h(App)
})
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const moduleA = {
state: {
name: 'module A',
initData: ''
},
mutations: {
INIT (state, payload) {
state.initData = 'Initialized A'
}
}
}
const moduleB = {
state: {
name: 'module B',
initData: ''
},
mutations: {
INIT (state, payload) {
state.initData = 'Initialized B'
}
}
}
const initPlugin = store => {
store.commit('INIT')
}
export default new Vuex.Store({
state: {},
mutations: {},
modules: {
a: moduleA,
b: moduleB
},
plugins: [initPlugin]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment