安装vuex
npm install vuex@3
模块化使用
src文件夹下创建store文件夹
store文件夹下创建index.js文件
import Vue from 'vue'
import Vuex from 'vuex'
import countOptions from "@/store/count";
import personOptions from "@/store/person";
Vue.use(Vuex)
export default new Vuex.Store({
modules:{
countAbout:countOptions,
personAbout:personOptions
}
})
修改main.js文件
import Vue from 'vue'
import App from './App.vue'
import vueResource from 'vue-resource'
import store from './store'
Vue.config.productionTip = false
Vue.use(vueResource)
new Vue({
render: h => h(App),
store,
beforeCreate() {
Vue.prototype.$bus=this
}
}).$mount('#app')