【发布时间】:2020-02-25 04:57:00
【问题描述】:
我正在使用 vue-bootstrap 使用 v-for 指令创建一些输入字段。我正在尝试做的基本上与this link 中提供的示例相同,但我不知道如何将我收集的数据获取到 v-model 指令中(我的意思是,从输入中获取数据)。
我可以手动完成并分配每个字段并将其映射到我的对象的 v-model 中,但如果有更好的方法来解决这个问题,那将非常有帮助。
这是几乎完全从示例页面复制的代码 (vue-js),但我的修改失败(使用 cmets):
<template>
<b-container fluid>
<code>{{result}}</code>
<b-row class="my-1" v-for="type in types" :key="type">
<b-col sm="3">
<label :for="`type-${type}`">Type {{ type }}:</label>
</b-col>
<b-col sm="9">
<!-- here I modified the v-model part -->
<b-form-input :id="`type-${type}`" :type="type" :v-model="`result.${type}`"></b-form-input>
</b-col>
<!-- here I added the same "v-model" that I placed into the previous line -->
<p>{{`result.${type}`}}</p>
</b-row>
</b-container>
</template>
<script>
export default {
data() {
return {
// here I placed the result object and I expected to obtain something like this:
/*
result: {
text: "the text",
password: "the password"
...
...
}
*/
result: {},
types: [
'text',
'password',
'email',
'number',
'url',
'tel',
'date',
`time`,
'range',
'color'
]
}
}
}
</script>
谁能解释我做错了什么?我试图在 v-for 语句中找到 "`type-${type}`" 的文档,但我找不到。
【问题讨论】:
标签: javascript vue.js vuejs2 bootstrap-vue