[英]vue this.array.find in methods/computed properties gives undefined
I have an array (approvalOptions) that i receive from getters in a component, from which i need to find a certain value.我有一个数组 (approvalOptions),我从组件中的 getter 接收到它,我需要从中找到某个值。
Things i have tried:我尝试过的事情:
methods: {
approvalDisplayName(value) {
console.log(this.approvalOptions)
return this.approvalOptions.find(it => it.key === value).displayName;
},
},
data() {
return {
approvalOptions: [...(objects with keys and values here)]
}
},
methods: {
approvalDisplayName(value) {
console.log(this.approvalOptions)
return this.approvalOptions.find(it => it.key === value).displayName;
},
},
All three times I get an error in the console that approvalOptions.find(...) doesnt exist.我在控制台中都收到了三个错误,即批准选项.find(...) 不存在。 The console.log also prints an array in the console so i really don't understand what is going on here. console.log 还在控制台中打印了一个数组,所以我真的不明白这里发生了什么。
Maybe this can help you也许这可以帮助你
computed: {
approvalOptions() {
return [
{ key: 1, displayName: "Name 1" },
{ key: 2, displayName: "Name 2" }
];
}
},
methods: {
approvalDisplayName(options, value) {
return options.find((it) => it.key === value).displayName;
}
},
created() {
console.log(this.approvalDisplayName(this.approvalOptions, 1));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.