Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript VueJS/Vuetify v-for中的不同色片,对照带有参数的对象进行检查:使用点符号表示颜色_Javascript_Vue.js_Vuejs2_Vuetify.js_Computed Properties - Fatal编程技术网

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]