【VUE】7.Vuex基本使用

1. 安装Vuex

npm install vuex --save

2. 导入Vuex包

import Vuex from 'vuex'

Vue.use(Vuex)

  

3. 创建store对象

const store = new Vuex.Store(
{
    // state 中存放的就是全局共享的数据
    state: {},
    mutations: {},
  action: {}
})

  

 

4. 将store 对象挂载到vue实例中,将store挂载到vue实例中,这样所有的组件就可以直接从store中获取全局的数据  -> main.js

import store 'store.js'
new Vue({ router, render: h => h(App), store }).$mount('#app')

  

posted @ 2020-06-08 11:04  WANG-X  阅读(142)  评论(0编辑  收藏  举报