I want to add a string from an array to v-model
, something like this:
<div v-for="(item, index) in items" :key="index">
<input :v-model="item.key" />
</div>
but this code doesn't work and after many time search I didn't find a right way to do this
See this fiddle for a working example . v-model
doesn't need the :
in front.
new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!',
items: [{
key: "test one"
},
{
key: "test two"
},
{
key: "test three"
}]
}
})
and the dom:
<script src="https://unpkg.com/vue"></script>
<div id="app">
<p>{{ message }}</p>
<div v-for="(item, index) in items" :key="index">
<input v-model="item.key" />
</div>
</div>
Docs link: Vue form bindings
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.