I'm trying to parameterise variable names so they can be passed as properties into my component. In the example below I want to use this to pass the names of the item variables into the array so I can selectively display them as columns in a table without the binding having to know the item variable names.
<div id="myApp">
<h2>parameterized variable names</h2>
<table>
<tr>
<th v-for="label in labels">{{label}}</th>
</tr>
<tr v-for="item in items">
<td v-for="label in labels">{{item.label}}</td>
</tr>
</table>
</div>
My Vue instance looks like this -
new Vue({
el: '#myApp',
data: {
labels:[
'text',
'value'
],
items:[
{text: 'One', value: 'A', something:'12'},
{text: 'Two', value: 'B', something:'67'},
{text: 'Three', value: 'C', something:'66'}
]
}
});
This doesn't work because it is attempting to render a variable called 'label' in the declaration {{item.label}}. How can I tell it that 'label' is not the literal variable name?