摘要:
Mutation 更改 Vuex 的 store 中的状态的唯一方法是提交 mutation。(官方希望我们使用mutation的方式去修改state) const store = new Vuex.Store({ state: { count: 1 }, mutations: { incremen 阅读全文
posted @ 2020-12-21 16:21
京鸿一瞥
阅读(288)
评论(0)
推荐(0)
摘要:
有时候我们需要从 store 中的 state 中派生出一些状态, Vuex 允许我们在 store 中定义“getter”(可以认为是 store 的计算属性)。就像计算属性一样,getter 的返回值会根据它的依赖被缓存起来,且只有当它的依赖值发生了改变才会被重新计算。 就和计算属性一样,处理出 阅读全文
posted @ 2020-12-21 15:49
京鸿一瞥
阅读(204)
评论(0)
推荐(0)
摘要:
使用 this.$store.state.count const Counter = { template: `<div>{{ count }}</div>`, computed: { count () { return this.$store.state.count } } } 当然,这里推荐用 阅读全文
posted @ 2020-12-21 11:36
京鸿一瞥
阅读(240)
评论(0)
推荐(0)
摘要:
作为一个刚开始用 vuex 的小白,我一开始的用法就是直接修改 state 的状态,后来看到官网 从组件的方法提交一个变更: methods: { increment() { this.$store.commit('increment') console.log(this.$store.state. 阅读全文
posted @ 2020-12-21 11:15
京鸿一瞥
阅读(1856)
评论(0)
推荐(0)
浙公网安备 33010602011771号