Vue.js Props

If you're just getting started with this series of Vue.js posts, you should start with the Vue.js Starter Page.

Vue.js uses these things called "props" to pass data from a parent component to a child component. Here's how:

Vue.js Props

This file is actually a combination of 2 different Vue files; App.vue (the parent component) and Muscle.vue (the child component).

Using Vue.js props you can take the data out of the child component and instead put it into the parent component and pass it to the child using props. The parent needs to hand it off and the child needs to receive it.

Hand off from the parent component (App.vue) vue file: App.vue line 69: The muscles data object is defined and on line 48 v-bind:muscles="muscles" is what hands off the data to the child component (Muscle.vue).

Receipt of data (prop) from App.vue within Muscle.vue is subtle; on line 21 you could have easily just have defined the entire data set under muscles but instead, by naming convention, it receives the prop data from the parent instead. The rest of the child component (Muscle.vue) continues to work exactly as if the data was defined on line 21.

Lines 22 and 23 represent validation; type:Array indicates the data type and reqired: true says it has to be there. These are good for a dev environment as the errors will appear in the browser console upon inspection.