【问题标题】:Vue3: Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'NewTodo'Vue3:未捕获的类型错误:代理上的“设置”:属性“NewTodo”的陷阱返回错误
【发布时间】:2022-01-10 07:12:51
【问题描述】:

我收到一条错误消息: 未捕获的类型错误:代理上的“设置”:陷阱为属性“NewTodo”返回错误

当我尝试重置子组件 (FormAddTodo.vue) 中的输入文本值时出现该错误。

App.vue:

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

<template>
  <div class="container mx-auto">
      <Todos :todos="todos" />
      <div class="py-8"></div>
      <FormAddTodo :NewTodo="newTodo" :Todos="todos" />
  </div>
</template>

FormAddTodo.vue:

<template>
    <div class="formAddTodo">
        <form @submit.prevent="handleAddTodo" class="addTodo">
            <input type="text" class="" 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>

【问题讨论】:

    标签: javascript vue.js vuejs3


    【解决方案1】:

    您正在使用v-model="NewTodo",其中NewTodo 是组件的道具。

    道具不会从孩子身上改变。

    使用不同的 v-model 变量,这对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-06
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多