1 new Vue({ 2 3 //data 4 data(){ 5 return { 6 count:0 7 } 8 }, 9 //view 10 template:`<div>{{count}}</div>`, 11 12 //actions 13 methods:{ 14 increment(){ 15 this.count++; 16 } 17 } 18 19 })


什么情况下使用Vuex?当开发大型的单页面应用.如果不打算开发大型的单页面应用store模式就够用.
const moduleA = { state: () => ({ ... }), mutations: { ... }, actions: { ... }, getters: { ... } } const moduleB = { state: () => ({ ... }), mutations: { ... }, actions: { ... } } const store = new Vuex.Store({ modules: { a: moduleA, b: moduleB } }) store.state.a // -> moduleA 的状态 store.state.b // -> moduleB 的状态
原文:https://www.cnblogs.com/lsb123/p/13254408.html