Why do I have en error "Unexpected mutation of "modelValue" prop" in Vue?

Viewed 2373

So i'm working with you and I have a select component, I created a modelValue prop which is an empty string, and passed it in v-model:

<select v-model="modelValue" @change="changeOption">
        <option 
        disabled 
        value="">
        Choose from the  list
        </option>
        <option 
        v-for="option in options" 
        :key="option.value" 
        :value="option.value">
            {{ option.name }}
        </option>
    </select>

props:{
            modelValue:{
                type: String
            },
            options:{
                type: Array,
                default: () => []
            }
        }

But for some reason it gives an error: Unexpected mutation of "modelValue" prop. I just started working with Vue so I'm not sure where this error could come from. I was following a tutorial and everything seemed to work there.

2 Answers
  1. create life cycle "computed"

    computed: { localModelValue: { get() { return this.modelValue }, }, },

  2. After that change v-model="modelValue" to v-model="localModelValue"

Related