vuex

Vuex 是一个专为vue.js应用程序开发的状态管理模式
state 单一状态树vue

npm install vuex
新建一个store文件夹,建立index.js
import Vue from 'vue'
import Vuex from 'vuex'

1.安装插件
Vue.use(vuex)
2.建立对象
const store = new Vuex.Store({
state :{
counter:1000
},
mutations:{ //修改状态,经过commit('')修改提交
modifyState(state){
state.counter++
}
},
actions :{ //异步修改状态

},
getters :{ //相似计算属性

},
modules:{vuex

}
})npm


3.导出
export dafault storeapp

4.在main.js中 注册vuex
import stroe form './store'
Vue.prototype.$store = store
new Vue({
el: '#app',
store,
render: h=>h(App)
methods:{
increment:function(){
this.$store.commit('modifyState')
}
}
})异步

相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息