因Vue组件之间值不能共享,所以需要通过内部指定属性进行传递。(PS:驼峰命名,标签引用是要用-隔开)
一,父类组件向子类组件传值
<body>
<div id="app">
<user-Parent-Comp></user-Parent-Comp>
</div>
</body>
<script>
var vm = new Vue({
el: '#app',
components: {
'userParentComp': {
template: '<h1>I am a parent component.---{
{parentVal}}<br/><userChildComp :childVal="fromParentVal"/></h1>',
data() {
return {
parentVal: 'I am the value of a parent class. ',
fromParentVal: 'I am a value from the parent class. '
}
},
components: {
'userChildComp': {
props: ['childVal'],
template: '<p>I am a child component.---{
{childVal}} </p>'