1

How do I set the first option as a default value in dropdownlist?

<select :disabled=true class="custom-select" v-model="Status">
      <option disabled value>Select Any</option>          
      <option v-for="status in statusList" v-bind:value="{StatusId:status.StatusId,StatusName:status.StatusName}" :key="status.StatusId">{{ status.StatusName }}</option>                    
</select>

Here v-model="Status" is an object. So, when I have set it like below It's not working:

data() {
    return {            
        Status: 1                                   
    };
},

Here, 1 is the id of first option.

1 Answer 1

1

Status needs to be an object as well if you want it to match.

data() {
  return {            
    Status: { StatusId: 1, StatusName: 'name' }                           
  }
}

All of the properties of your default Status will need to match one of the options in order for it to be selected.

But note that there is probably no good reason here to use this pattern of setting the option value to an object. Better to set it to the StatusId, and use that selected id or a computed to process the option wherever you need to use it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.