





























const counterStore = hamiVuex.store({
// 设置一个唯一名称,方便调试程序和显示错误信息
$name: 'counter',
// 定义状态
$state: {
count: 0,
},
// 定义一个 getter,和 Vue computed 类似
get double() {
return this.count * 2
},
// 定义一个函数,等价于 Vuex action
increment() {
// $patch 是内置的 Vuex mutation,用于更新状态
this.$patch({
count: this.count + 1
})
},
})
// 在 Vue 组件中使用
console.log(counterStore.count)
console.log(counterStore.increment())
console.log(counterStore.double)
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。