Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element UI select doesn't work with object as value

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

like image 744
Denis Stephanov Avatar asked Apr 22 '26 18:04

Denis Stephanov


1 Answers

Based on select-attributes just add value-key="id" to select component to give the select an unique identifier :

<el-select v-model="value" placeholder="Select" value-key="id">
like image 65
Boussadjra Brahim Avatar answered Apr 26 '26 15:04

Boussadjra Brahim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!