3

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

Pierce O'Neill
  • 385
  • 9
  • 22
Tessa Muliawati
  • 85
  • 1
  • 1
  • 4

2 Answers2

4

Try this.I think this will work.

<v-select
  v-model="selected"
  :options="options">
</v-select>


data: () {
  return {
    selected: 'Option 1',
    options: ["Option 1","Option 2","Option 3"]
  }
},
Bhaskararao Gummidi
  • 2,513
  • 1
  • 12
  • 15
3

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

tony19
  • 125,647
  • 18
  • 229
  • 307
mava
  • 2,544
  • 1
  • 10
  • 17