How to make this work:
JavaScript
x
4
1
<div v-for="index in 4">
2
<input v-model="'invoice_' + index" >
3
</div>
4
just like this:
JavaScript
1
4
1
<div v-for="index in 4">
2
<input v-model="invoice_1" >
3
</div>
4
Advertisement
Answer
It could be better if you put all the invoices_s variables in a single object and then refer to them by key, something like follows:
JavaScript
1
11
11
1
new Vue({
2
el: '#app',
3
data: {
4
invoices: {
5
invoice_1: '1',
6
invoice_2: '2',
7
invoice_3: '3',
8
invoice_4: '4'
9
}
10
}
11
})
JavaScript
1
7
1
<script src="https://unpkg.com/vue@2.5.3/dist/vue.js"></script>
2
3
<div id="app">
4
<div v-for="index in 4">
5
<input v-model="invoices['invoice_' + index]">
6
</div>
7
</div>