1. 安装 vuex 依赖包
npm install vuex --save
2. 导入 vuex 包
import Vuex from 'vuex'Vue.use(Vuex)
3. 创建 store 对象
const store = new Vuex.Store({// state 中存放的就是全局共享的数据state: { count: 0 }})
4. 将 store 对象挂载到 vue 实例中
new Vue({el: '#app',render: h => h(app),router,// 将创建的共享数据对象,挂载到 Vue 实例中// 所有的组件,就可以直接从 store 中获取全局的数据了store})
