我拼命地想用我的道具‘数据’和一个Foreach。
当我把我的数据放在一个“测试”数据中时,它就起作用了。
示例:
data() {
return {
postForm: this.$vform({}),
test: [{"name":"Couleur yeux","id":3,"answer":null},{"name":"Hanches","id":6,"answer":"'Test'"}],
}
},
computed: {
},
methods: {
createForm() {
this.test.forEach((data) => {
if (data.answer) {
this.$set(this.postForm, data.id, data.answer)
}
})
}
},
但如果我直接用我的道具,就不管用了。 我有一条消息“this.datas.foreach不是一个函数”。
但是我的道具和我的“测试”数据完全一样的数据,一样的结构。
不工作:
this.datas.forEach((data) => {
if (data.answer) {
this.$set(this.postForm, data.id, data.answer)
}
})
我还尝试将我的道具转换为数据(),但它没有工作
data() {
return {
postForm: this.$vform({}),
test: this.datas
},
“This.Datas.Foreach不是函数”
这意味着datas
不是数组实例,因为foreach
是来自数组原型的方法。