It would work unless you've defined your data like this:
data() {
return {
cars: [ ... ],
persons: [ ... ],
componentData: [
{ name: TestPane, props: { data: this.cars }, id: 1 },
{ name: TestPane, props: { data: this.persons }, id: 2 },
]
}
}
this.cars and this.persons aren't accessible when you define componentData. Use a computed to maintain reactivity:
new Vue({
el: "#app",
data() {
return {
cars: [ ... ],
persons: [ ... ]
}
},
computed: {
componentData() {
return [
{ name: TestPane, props: { data: this.cars }, id: 1 },
{ name: TestPane, props: { data: this.persons }, id: 2 },
]
}
}
});
EDIT: Here's a demo
const TestPane = {
template: `
<div class="pane">
{{ data }}
</div>
`,
props: ['data']
}
/***** APP *****/
new Vue({
el: "#app",
data() {
return {
cars: ['honda', 'ferrari'],
persons: ['Bob', 'Mary']
}
},
computed: {
componentData() {
return [
{ name: TestPane, props: { data: this.cars }, id: 1 },
{ name: TestPane, props: { data: this.persons }, id: 2 },
]
}
}
});
.pane {
padding: 12px;
background: #dddddd;
margin: 4px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div v-for="component in componentData" :key="component.id">
<component v-bind:is="component.name" v-bind="component.props">
</component>
</div>
</div>
v-bindthat is same like doing:="component.props"it makes no sense. you need to write what you want to pass likev-bind:datacomponentDatais defined in the samedatablock ascarsandpersons, that's the problem. They won't exist at the time you definecomponentData, even if they are listed above. (Thev-bindsyntax is valid though.)TestPanethis:created(){console.log(this.data);}?