随笔分类 -  vuex

state mutations actions 使用总结(小白式总结)
摘要:1、State this.$store.state.count 不要直接改变 state, 通过提交 mutation 的方式,而非直接改变 store.state.count 2、mutatioins this.$store.commit('方法名','载荷(参数) { Object } 对象的形 阅读全文
posted @ 2021-02-25 10:17 京鸿一瞥 阅读(562) 评论(0) 推荐(0)
4、actions
摘要:在 mutation 中混合异步调用会导致你的程序很难调试。例如,当你调用了两个包含异步回调的 mutation 来改变状态,你怎么知道什么时候回调和哪个先回调呢?这就是为什么我们要区分这两个概念。在 Vuex 中,mutation 都是同步事务. store.commit('increment') 阅读全文
posted @ 2020-12-21 17:06 京鸿一瞥 阅读(365) 评论(0) 推荐(0)
3、mutations
摘要:Mutation 更改 Vuex 的 store 中的状态的唯一方法是提交 mutation。(官方希望我们使用mutation的方式去修改state) const store = new Vuex.Store({ state: { count: 1 }, mutations: { incremen 阅读全文
posted @ 2020-12-21 16:21 京鸿一瞥 阅读(284) 评论(0) 推荐(0)
2、getter
摘要:有时候我们需要从 store 中的 state 中派生出一些状态, Vuex 允许我们在 store 中定义“getter”(可以认为是 store 的计算属性)。就像计算属性一样,getter 的返回值会根据它的依赖被缓存起来,且只有当它的依赖值发生了改变才会被重新计算。 就和计算属性一样,处理出 阅读全文
posted @ 2020-12-21 15:49 京鸿一瞥 阅读(198) 评论(0) 推荐(0)
1、State
摘要:使用 this.$store.state.count const Counter = { template: `<div>{{ count }}</div>`, computed: { count () { return this.$store.state.count } } } 当然,这里推荐用 阅读全文
posted @ 2020-12-21 11:36 京鸿一瞥 阅读(233) 评论(0) 推荐(0)
vuex中使用commit提交mutation来修改state的原因
摘要:作为一个刚开始用 vuex 的小白,我一开始的用法就是直接修改 state 的状态,后来看到官网 从组件的方法提交一个变更: methods: { increment() { this.$store.commit('increment') console.log(this.$store.state. 阅读全文
posted @ 2020-12-21 11:15 京鸿一瞥 阅读(1850) 评论(0) 推荐(0)