//html<div id="app"> <p>{{ count }}</p> <p> <button @click="increment">+</button> <button @click="decrement">-</button> </p></div>//js// make sure to call Vue.use(Vuex) if using a module systemconst store = new Vuex.Store({ state: { count: 0 }, mutations: { increment: state => state.count++, decrement: state => state.count-- }})new Vue({ el: '#app', computed: { count () { return store.state.count } }, methods: { increment () { store.commit('increment') }, decrement () { store.commit('decrement') } }})在以上代码中,<button @click="increment">+</button><button @click="decrement">-</button>为什么不是methods.increment()?
添加回答
举报
0/150
提交
取消