[英]Using object as Vue Select options
I know, Vue Select docs specify that options should be an array, but is there a way around it?我知道,Vue Select 文档指定 options 应该是一个数组,但是有没有办法解决它? I want to use object keys as values and object values as labels.我想使用对象键作为值和对象值作为标签。
My data:我的数据:
obj: {
value: 'en',
options: {
'ar': 'Arabic',
'ast': 'Asturian',
'en':' English'
}
}
<v-select
v-model="obj.value"
:options="Object.keys(obj.options)"
>
I know i can use keys as options that way, but I have no idea how to use values as labels.我知道我可以这样使用键作为选项,但我不知道如何使用值作为标签。 Any tips?有小费吗?
There are multiple ways you could do that but one options is:有多种方法可以做到这一点,但一种选择是:
<v-select v-model="obj.value" :options="obj.options" :reduce="val => val.code"/>
Only change to your data should be that the obj.options should look like below:对您的数据的唯一更改应该是 obj.options 应如下所示:
obj: {
value: "en",
options: [
{ label: "Arabic", code: "ar" },
{ label: "Asturian", code: "ast" },
{ label: "English", code: "en" }
]
}
Relevant documentation transforming-selections相关文档转换选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.