父组件中需要四个步骤:
(1)在data中定义需要传递的值
data () {
return {
parentMsg : '父组件传值给子组件的值'
}
},
(2)调用子组件import 自己起个名 from '子组件路径'(将子组件引入父组件中)
(3)注册所调用的子组件
在components中注册,因为可能有多个子组件,所以家“s”
components: {
child //刚刚调用是起的名,要一致,例如为child
},
(4)在父组件中引用子组件
<child :parentMsg='parentMsg'></child>
父组件子组件中接收传递的值:
props: ['parentMsg']
子组件
网友评论