【发布时间】:2019-03-22 07:59:19
【问题描述】:
我可以在按钮点击时动态添加文本框。我的问题是我无法设置动态 ID 和值。
<div id="app">
<div>
<button class="button btn-primary" @click="addRow">Add row</button>
</div>
<div v-for="row in rows">
<button-counter></button-counter>
</div>
</div>
<script>
Vue.component('button-counter', {
template: '<input type="text" style="margin-top: 10px;" ><br>'
})
var app = new Vue({
el: "#app",
data: {
rows: [],
count:0
},
methods: {
addRow: function () {
var txtCount=++this.count;
id='txt_'+txtCount;
this.rows.push({ title: "first", description: "textbox1" });
}
}
});
</script>
This is my code.
我在组件上创建了输入并创建了一个 vue 实例。单击添加行按钮时,它将添加一个新的文本框。但我不知道为文本框绑定 id 和值。
【问题讨论】:
标签: javascript vue.js vuejs2 vue-component