Vuex
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luobosiji/article/details/90696216 Vuex 状态管理 运行机制 Vuex 使用 npm install vuex --save import Vuex from 'vuex' Vue.use(Vuex) const app = new Vue ( { el : '#app' , // 把 store 对象提供给 “store” 选项,这可以把 store 的实例注入所有的子组件 //需调用 Vue.use(Vuex) store , //子组件能通过 this.$store 访问到。 } ) 通过 this.$store.state.xxx 来访问 通过 this.$store.commit('xxx',{arg}) 来提交修改数据操作(Mutation) 通过 this.$store.dispatch('xxx',{arg}) 来进行异步修改数据操作(Action) 通过 this.$store.getter.xxx 来访问store的计算属性 store const store = new Vuex . Store ( { state : { count : 1 , //响应式数据 todos : [ { id : 1 , text : '...