Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  137] [ 1]  / answers: 1 / hits: 20284  / 9 Years ago, mon, november 9, 2015, 12:00:00

I'm working through the guide for learning vue.js, got to the section on props, and ran into a question.



I understand that child components have isolated scops and we use the props configuration to pass data into it from the parent, but when I try it out I can't get it to work.



I have the example I'm working on up on js fiddle:



var vm = new Vue({
el: '#app',
// data from my parent that I want to pass to the child component
data:{
greeting: 'hi'
},
components:{
'person-container':{

// passing in the 'greeting' property from the parent to the child component
props:['greeting'],

// setting data locally for the child
data: function (){
return { name: 'Chris' };
},

// using both local and parent data in the child's template
template: '<div> {{ greeting }}, {{ name }}</div>'
}
}
});


When I run the above code, my output is only:




, Chris




The data local to the child component renders fine, but the passed in parent's data is either not coming through or is not properly rendering.



I don't see any errors in the javascript console and the template is rendering.



Am I misunderstanding how the props are supposed to be passed in?


More From » vue.js

 Answers
7

You have to bind the value to the component prop like this:



<person-container v-bind:greeting=greeting></person-container>


Jsfiddle
https://jsfiddle.net/y8b6xr67/



Answered here:
Vue JS rc-1 Passing Data Through Props Not Working


[#64459] Friday, November 6, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondorlandok

Total Points: 530
Total Questions: 110
Total Answers: 96

Location: Lebanon
Member since Wed, Dec 21, 2022
1 Year ago
;