3

I am working on a Vue app made with element UI and I have a bunch of el-select whose el-options need to have default values, meaning the form select fields already have one option pre-selected (of course the user can still choose other options). I cannot find any attribute in the official doc https://element.eleme.io/#/en-US/component/select#select But there should be a way to achieve this right?

This is my code

<el-form-item label="some label" prop="someprop">
    <el-select v-model="form.status" filterable clearable>
        <el-option
            v-for="(item, index) in config.status"
            :key="index"
            :label="item"
            :value="index"
            how to have default option here??
            >
        </el-option>
    </el-select>
</el-form-item>
Andrea D_
  • 2,028
  • 3
  • 15
  • 38
  • Can you set the default value in your model's `form.status` field? – nemesv Dec 15 '21 at 11:32
  • 1
    This question has already been answered: https://stackoverflow.com/questions/41122028/set-default-value-to-option-select-menu/41123073 – nucleaR Dec 15 '21 at 12:47
  • Does this answer your question? [Set default value to option select menu](https://stackoverflow.com/questions/41122028/set-default-value-to-option-select-menu) – nucleaR Dec 15 '21 at 12:50

1 Answers1

1

Just put in the form.status the indexes that should be pre-selected. Vue will take care of the rest.

data(){
   return {
      form: { status: ['thisWillBePreSelected'], },
   }
}
Raffobaffo
  • 2,806
  • 9
  • 22