输入值不接受 vue js 上的对象



我的 vue js 应用程序上有输入类型文本

这是我的代码:

<input type="text" v-model="answer[index]" >

更新的代码:

<table>
<tr v-for="(question_overall, index) in questions">
<td>
{{ question_overall.question }}
<div>
<input type="text" :value="{id: question_overall.id , answer:  ??}" v-model="answer[index]" >
</div>
{{ answer[index] }}
</td>
</tr>
</table>
data: function () {
return {
questions: [],
answer:{
id: null,
answer: null,
},
}
},

我希望如果我像这样呼应 v 模型:

{{ answer[index] }}

输出将是:

{ "id": 1, "answer": "the value of this answer is from what I type in" }

你能帮我解决我的问题吗?谢谢。

请仔细看看 vue.js 文档

如何使用V模型:

<input type="text" v-model="text.answer" />

脚本:

export default {
data: () => ({
text: {
id: 1,
text: ''
}
})
}

使用 v 模型的另一种方法

脚本:

export default {
data: () => ({
text: {
id: 1,
text: ''
}
}),
methods: {
value_changing(event) {
this.text = event.target.value
}
}
}

如果你想要一个带有for循环的v模型,看看这里

最新更新