Javascript VueJS/Vuetify v-for中的不同色片,对照带有参数的对象进行检查:使用点符号表示颜色
我试图通过使用一个方法设置Javascript VueJS/Vuetify v-for中的不同色片,对照带有参数的对象进行检查:使用点符号表示颜色,javascript,vue.js,vuejs2,vuetify.js,computed-properties,Javascript,Vue.js,Vuejs2,Vuetify.js,Computed Properties,我试图通过使用一个方法设置v-chip的颜色,传递一个参数并尝试使用点表示法返回一个颜色字符串: <v-chip :color="stateColor(bug.workflow_state)" text-color="white">{{ bug.workflow_state }}</v-chip> …在数据函数中设置。我只想返回一个la: stateColor (bugState) { return this.stateColors.bugState } 但是th
v-chip
的颜色,传递一个参数并尝试使用点表示法返回一个颜色字符串:
<v-chip :color="stateColor(bug.workflow_state)" text-color="white">{{ bug.workflow_state }}</v-chip>
…在数据函数中设置。我只想返回一个la:
stateColor (bugState) {
return this.stateColors.bugState
}
但是this.stateColors.bugState
未定义。传入的工作流状态将与键匹配,没有例外。这似乎更适合作为计算属性,但我也遇到了点表示法返回预期结果的问题。我的尝试是这样的:
stateColor: function () {
return function (bugState) {
return this.stateColors.bugState
}
}
在两次尝试中,
this.stateColors.open
确实返回绿色,但是this.stateColors.bugState
其中bugState实际上是“open”返回未定义typeof(bugState)
绝对是一个字符串。我只是在寻找一种干净的方法来实现这一点,而不需要大量的if检查,我知道这是可行的。您只是要求使用bugState
属性,该属性可能不存在
相反,请求与bugState
变量匹配的密钥:
return this.stateColors[bugState]
我真的发现了。不过还是万分感谢!
return this.stateColors[bugState]