2019-08-19

2019-08-19  本文已影响0人  爱吃瓜的猹_ad3b

一、先配置vuex

1.运行 cnpm i vuex -S

2.导入包

import Vuex from 'vuex'

3.注册vuex到vue中

Vue.use(Vuex)

4.new Vuex.Store()实例,得到一个数据仓储对象

Var store = new Vuex.Store({

state:{},  //相当于组件中的data,专门用来存储数据

mutations:{}//相当于组件中的methods,操作state中的数据

})

5.将vuex创建的store挂载到App实例上

const App = new Vue({

el:'#app',

render:c => c(App),

store//挂载store

上一篇 下一篇

猜你喜欢

热点阅读