【发布时间】:2018-08-13 17:13:32
【问题描述】:
我的用例是这样的,
- 我循环遍历一组对象以填充下拉菜单。
- 如果我使用 v-model 下拉列表,我只能获取对象 ID 或名称。但我可以同时获得 id 和 name。
- 所以我需要计算属性来查找所选对象的 id。
这是我的 v-select
<v-select
label="Select an item"
:items="items"
item-text="name"
v-model="item_name">
</v-select>
这是我的计算属性
computed: {
id() {
this.items.forEach(element => {
if (element.name == this.item_name) {
return (this.item = element.id);
}
});
}
}
我希望 {{item}} 打印所选项目的 id 的计算属性出了什么问题,但它没有。
【问题讨论】:
-
尝试:返回 this.item.forEach()...