【发布时间】:2021-02-07 02:52:26
【问题描述】:
类似于在 vuex 中使用 mapFunction(['name'])。
在学习 vuex 功能时,我遇到了它的 mapfunctions,它可以用相同的名称或不同的名称映射所需的属性。
我想实现一个相似之处,其中变量的名称和值分别作为键值对映射到对象。
在 vanilla javaScript 中已经可以了吗?
参考: vuex documentation vuex mapping guide article
ps:请查看参考资料以获得更清晰的功能说明
前->
`
variable var_name1='var_value1'
variable var_name2='var_value2'
//note this is the format of the vuex where the name of a mapped property will remain the same
obj={[var_name1,var_name2]}
//the above should be equivalent to this
obj={
var_name1='var_value1',
var_name2='var_value2',
}
`
【问题讨论】:
标签: javascript object variables mapping vuex