美文网首页
父组件传值给子组件props

父组件传值给子组件props

作者: 了彧 | 来源:发表于2018-11-20 15:57 被阅读0次

    父组件中需要四个步骤:

      (1)在data中定义需要传递的值

          data () {

            return {

              parentMsg : '父组件传值给子组件的值'

            }

          },

      (2)调用子组件import 自己起个名 from '子组件路径'(将子组件引入父组件中)

      (3)注册所调用的子组件

          在components中注册,因为可能有多个子组件,所以家“s”

          components: {

            child //刚刚调用是起的名,要一致,例如为child

          },

      (4)在父组件中引用子组件

          <child :parentMsg='parentMsg'></child>

    父组件

      子组件中接收传递的值:

      props: ['parentMsg']

    子组件

    相关文章

      网友评论

          本文标题:父组件传值给子组件props

          本文链接:https://www.haomeiwen.com/subject/fedxqqtx.html