Home > Enterprise >  Vue3: Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'NewTodo
Vue3: Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'NewTodo

Time:01-10

I got an error message: Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'NewTodo'

That error appear when im trying to reset the input text value inside child component (FormAddTodo.vue).

App.vue:

export default {
  data(){
    return{
      todos: [],
      newTodo: ""
    }
  },
  components: {
    Todos,
    FormAddTodo
  }
}
</script>

<template>
  <div >
      <Todos :todos="todos" />
      <div ></div>
      <FormAddTodo :NewTodo="newTodo" :Todos="todos" />
  </div>
</template>

FormAddTodo.vue:

<template>
    <div >
        <form @submit.prevent="handleAddTodo" >
            <input type="text"  placeholder="type new todo here..." v-model="NewTodo">
        </form>
    </div>
</template>

<script>
    export default {
        props: ['NewTodo', 'Todos'],
        methods: {
            handleAddTodo(){
                const colors = ["cyan", "blue", "indigo", "pink"]
                const todo = {
                    id: Math.random(),
                    content: this.NewTodo,
                    color: colors[Math.floor(Math.random() * ((colors.length-1) - 0   1)   0)]
                }

                this.Todos.push(todo)
                this.NewTodo = '' // this line throw the error
            }
        }
    }
</script>

CodePudding user response:

You are using v-model="NewTodo" where NewTodo is the props of the component.

Props are not ment to be changed from the child.

Use a diffrent v-model variable and this will work for you.

  •  Tags:  
  • Related