console
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment: state => state.count++,
},
actions: {
increment(context) {
context.commit("increment")
},
Aincrement({
commit
}) {
setTimeout(() => {
alert("延迟了5秒")
commit("increment")
},
5000)
}
}
})
const Counter = {
template: `<p>{{ count }}</p>`,
computed: {
count() {
return store.state.count
}
}
}
const app = new Vue({
el: "#app",
store,
components: {
Counter
},
template: `
<div class = "app" >
<button @click="increment">+</button>
<button @click="Aincrement">+(async)</button>
<counter > </counter>
</div > `,
methods: {
...Vuex.mapActions([
'increment','Aincrement']),
}
})
<div id="app" class="app">
</div>
.app {
background-color: #ffffff
}