admin管理员组文章数量:1312778
I am trying to use Element UI's Select with whole objects as values. As you can see in my sample, the selected value is changing but the label of current value doesn't. I have no idea why. Also, all labels in select options are bold, but it should be only selected one.
script:
data() {
return {
options: [
{
id: 1,
type: 'USER',
age: 15
}, {
id: 2,
type: 'ADMIN',
age: 22
}
],
value: null
}
}
template:
<el-select v-model="value" placeholder="Select">
<el-option
v-for="item in options"
:key="item.id"
:label="item.type"
:value="item">
</el-option>
</el-select>
Demo:
I am trying to use Element UI's Select with whole objects as values. As you can see in my sample, the selected value is changing but the label of current value doesn't. I have no idea why. Also, all labels in select options are bold, but it should be only selected one.
script:
data() {
return {
options: [
{
id: 1,
type: 'USER',
age: 15
}, {
id: 2,
type: 'ADMIN',
age: 22
}
],
value: null
}
}
template:
<el-select v-model="value" placeholder="Select">
<el-option
v-for="item in options"
:key="item.id"
:label="item.type"
:value="item">
</el-option>
</el-select>
Demo: https://codepen.io/peter-peter-the-typescripter/pen/qBNeKEp
Share Improve this question edited Nov 23, 2020 at 21:47 Boussadjra Brahim 1 asked Nov 23, 2020 at 21:06 Denis StephanovDenis Stephanov 5,30131 gold badges93 silver badges189 bronze badges1 Answer
Reset to default 9Based on select-attributes just add value-key="id"
to select ponent to give the select an unique identifier :
<el-select v-model="value" placeholder="Select" value-key="id">
本文标签: javascriptElement UI select doesn39t work with object as valueStack Overflow
版权声明:本文标题:javascript - Element UI select doesn't work with object as value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741869235a2402095.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论