export default {
created() {
}
methods: {
getData: async function() {
await this.$store.dispatch('getNote')
console.log(this.$store.state.data)
}
//不可用 因为actions里定义的是异步函数,所以dispatch方法是在最后执行的,因此此时打印出来的this.store.state.data是原始数据,未发生更改,所以一定要使用异步函数
getData: async function() {
await this.$store.dispatch('getNote')
console.log(this.$store.state.data)
}
//此时打印出的this.store.state.data是新数据
}
}