WoJ WoJ - 1 year ago 76
Javascript Question

How to pass data to a child component?

I am learning

and the answer to my question is in the documentation for dynamic props. I however fail to have in working in practice for my data structure.

My intent is to have a custom component
fed with data from the

Vue.component('cell', {
props: cell,
template: '<div>day is {{ cell.name }}</div>'

new Vue({
el: '#container',
data: {
"week": {
"today": {
"name": "Monday"
"tomorrow": {
"name": "Tuesday"

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>

<div id="container">
<cell v-bind:cell="week.today"></cell>
<cell v-bind:cell="week.tomorrow"></cell>

(this snippet does not run at all, not sure if vue.js is supported. I also have a JSFiddle to test on)

The expected result is

<div>day is Monday</div>
<div>day is Tuesday</div>

The output is empty, so I believe that there is something fundamentally wrong with my code. What is it?

Answer Source

props must be an array or object, so basically:

props: ['cell']


props: {
   cell: {
     // options

but not:

props: cell

I've fixed the fiddle for you here:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download