Vuex 入门教程:使用 Vuex 管理状态
<div id='app'>
<button @click='increment'>+</button>
<p>{{ $store.state.count }}</p>
</div>
<script>
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increase(state) {
state.count++
}
}
})
var vm = new Vue({
el: '#app',
store,
methods: {
increment() {
this.$store.commit('increase')
}
}
})
</script>
AI 优化版
原文地址:https://www.cveoy.top/t/topic/n8b3 著作权归作者所有。请勿转载和采集!