vue.js v-select default value

Tessa Muliawati picture Tessa Muliawati · Jan 10, 2019 · Viewed 9.6k times · Source

I want to make a default value of the select option using vue.js

here is my code

 <v-select
        v-model="contact.title"
        :options="['Mr','Mrs','Ms']">
      </v-select>

and

export default {
 props: {
  contact: {
  type: Object,
  required: true,
 },

titles: {
     type: Array,
     required: true,
   },
  },
};

thanks

Answer

mava picture mava · Jan 10, 2019

Mutating a prop is not best practice in vue. You could do it like:

<v-select
    v-model="selected"
    :options="['Mr','Mrs','Ms']">
</v-select>


data: function () {
  return {
    selected: '' || 'defaultValue'
  }
},

This way you are not mutating the prop and you easily can set a default value.
If you want to pass the data to the parent look at:
Pass data to parent