我收到了一条错误消息:Uncaught TypeError:'set‘on proxy: trap为属性'NewTodo'返回falsish
当im试图重置子组件(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>发布于 2022-05-04 11:02:17
我还面临过其他情况。这是一个提示,供其他人在使用Uncaught TypeError: 'set' on proxy: trap returned falsish for property xxxxxx时面临this.$refs.componentName.propertyname = value;问题时,为了解决这个问题,可以使用变量。
例如
<component-name :propertyname="variableA"><script>
export default = {
components: {
componentName,
},
data() {
variableA: 'default',
},
methods: {
changeValue(){
this.variableA = 'I_am_a_newValue';
},
},
}
</script>https://stackoverflow.com/questions/70648897
复制相似问题