Dynamic Textbox Menggunkan Vue Js
<div id="app">
<button v-on:click="addField(0)"class="btn btn-xs btn-primary">Add</button>
<div id="kmp"></div>
<div v-for="field in fields">
<input type="text" v-model="field.nama">
<button class="btn btn-danger btn-xs" @click="removeField($index)">remove row</button>
</div>
</div>
<script type="text/javascript">
new Vue ({
el:"#app",
data:{
fields:[
{nama:'aditya'},
]
},
methods:{
addField:function(index){
try {
this.fields.push({nama:''});
} catch(e)
{
console.log(e);
}
},
removeField: function (index) {
this.fields.splice(index, 1);
},
}
})
</script>
Demo