Home > OS >  Set a default selected option in vueJS select list
Set a default selected option in vueJS select list

Time:06-22

In my vueJS application I have following select option in a form

<!-- Schedule type -->
<div >
    <dashboard-input-label  identifier="schedule_type">
        Schedule type
    </dashboard-input-label>
    <div >
        <validator-v2
            :identifier="identifier"
            :rules="rules.schedule_type"
        >    
            <cs-dashboard-select
                :options="[
                    { value: '1', label: 'On duty'},
                    { value: '2', label: 'On vacation'},
                    { value: '3', label: 'Training'},
                    { value: '4', label: 'Sick leave'},
                ]"
                name="schedule_type"
                v-model="selectedValue"
            > Select type
            </cs-dashboard-select>
        </validator-v2>
    </div>    
</div>
<!-- Schedule type -->

How can I make the option 1, On duty as the default selected value?

I tried using

{ value: '1', label: 'On duty', selected},

but it was not working....

CodePudding user response:

you directly bind value with selectedValue.

data(){
   return {
      selectedValue : '3'
   }
}

if default value is based on props than,

props: {
  selecedValue : {
      default: '3',
      type: String,
  }
  • Related