This article is an example for us to analyze the attributes of props in Vue, for your reference, the specific contents are as follows
Passing Data using Props
The scope of the component instance is isolated. This means that the parent component's data cannot and should not be referenced directly within the subassembly's template. You can use props to pass data to a subassembly.
"Prop" is a field of component data that is expected to pass from the parent component. Subcomponents need to explicitly declare props with the props option:
Vue.component (' child ', {
//Declaration props
Props: [' msg '],
///prop can be used in the template
//can be set with ' this.msg '
Template: ' <span>{{msg}}</span> '
})
Then pass it to a normal string:
<child msg= "Hello!" ></child>
Example
Wrong wording:
Correct wording:
Props incoming multiple data (order issue)
First type:
Html
<div id= "App1" >
<child msg= "hello!" ></child>
<child nihao= "hello1!" ></child>
<child nisha= "hello2!" ></child>
</div>
Js
Vue.config.debug = true;
Vue.component (' child ', {
//Declare the props
props: [' msg ', ' Nihao ', ' Nisha '],
//The prop can be used inside Templates, and would also
//be set as ' this.msg '
Template: ' <span>{{msg}}{{NIHAO}}{{NISHA}}</SPAN&G t; ',
/*data:function () {return
{
msg: ' Boy '
}
}*/
});
var vm = new Vue ({
el: ' #app1 '
})
Result: hello! hello1! hello2!
The second type:
Html
<div id= "App1" >
<child msg= "hello!" ></child>
<child nihao= "hello1!" ></child>
<child nisha= "hello2!" ></child>
</div>
Js
Vue.config.debug = true;
Vue.component (' child ', {
//Declare the props
props: [' msg ', ' Nihao ', ' Nisha '],
//The prop can be used inside t Emplates, and would also
//be set as ' this.msg '
Template: ' <span>123{{msg}}{{nihao}}{{nisha}}</span& gt; ',
/*data:function () {return
{
msg: ' Boy '
}
}*/
});
var vm = new Vue ({
el: ' #app1 '
})
Result: 123hello! 123hello1! 123hello2!
The third type:
Html
<div id= "App1" >
<child msg= "hello!" ></child>
<child nihao= "hello1!" ></child>
<child nisha= "hello2!" ></child>
</div>
Js
Vue.config.debug = true;
Vue.component (' child ', {
//Declare the props
props: [' msg ', ' Nihao ', ' Nisha '],
//The prop can be used inside t Emplates, and would also
//be set as ' this.msg '
Template: ' <span>{{msg}}{{nihao}}{{nisha}}123</span& gt; ',
/*data:function () {return
{
msg: ' Boy '
}
}*/
});
var vm = new Vue ({
el: ' #app1 '
})
Result: hello! 123 hello1! 123 hello2!123
The fourth kind:
Html
<div id= "App1" >
<child msg= "hello!" ></child>
<child nihao= "hello1!" ></child>
<child nisha= "hello2!" ></child>
</div>
Js
Vue.config.debug = true;
Vue.component (' child ', {
//Declare the props
props: [' msg ', ' Nihao ', ' Nisha '],
//The prop can be used inside t Emplates, and would also
//be set as ' this.msg '
Template: ' <span>{{msg}}123{{nihao}}{{nisha}}123</ Span> ',
/*data:function () {return
{
msg: ' Boy '
}
}*/
});
var vm = new Vue ({
el: ' #app1 '
})
Result: hello! 123 123hello1! 123hello2!
Conclusion:
Passing in multiple data in props is if additional elements or characters are added to the parent component's template class:
1-Add in front-each subassembly is rendered in front of it plus
2-Add on the last side-each subassembly will be rendered with the following
3-Join in the middle-he is preceded by a subassembly followed by a subassembly followed by a sub component
Reference: http://cn.vuejs.org/guide/components.html
This article has been organized into the "Vue.js front-end component Learning course", welcome to learn to read.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.