V
V
vikas_web2022-03-23 14:32:08
Vue.js
vikas_web, 2022-03-23 14:32:08

How to fix the mutation error?

gives 2:19 error Unexpected mutation of "modelValue" prop vue/no-mutating-props, i.e.
swears at this line


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

<script>
  export default {
    name: 'my-select',
    props: {
      modelValue: {
        type: String
      },
      options: {
        type: Array,
        default: ()=>  []
      }
    },
    methods: {
      changeOption(event) {
        this.$emit('update:modelValue', event.target.value);
      }
    }
  }
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2022-03-23
@vikas_web

change v-model to :value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question