各位大大,前周看了阮大大关于函数式编程介绍Ramda.js学习了下。
但应用在Vuex的框架下,关于mutaions state赋值不知正确的姿势如何?
mutations example 假设通过函数式编程计算后要变更count值:
const store = new Vuex.Store({
state: {
count: 1
},
mutations: {
increment (state) {
// 方式1: 这样无法变更值
state = R.assoc('count', 3, state)
// 方式2: 把count包进去另外个package object (这样可以变更值)
state.package = R.assoc('count', 3, state.package)
}
}
})
请问如果要使用Ramda.js正确的赋值方式姿势如何??
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...