search

Home  >  Q&A  >  body text

javascript - vue的组件可以传children进去的吗?

<my-component>something</my-component>
<!--怎么在my-component里获得something ??-->
<parent-component>
    <my-component>
        <child1></child1> <!--怎么在my-component里获得child1 ??-->
    </my-component>
    <my-component>
        <child2></child2> <!--怎么在my-component里获得child2 ??-->
    </my-component>
<parent-component>

在React里是通过this.props.children获得

通过v-ref只能在定义template的时候才能静态获得子对象

大家讲道理大家讲道理2902 days ago275

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-04-10 17:14:20

    http://vuejs.org/guide/components.html#Child_Component_Refs

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-10 17:14:20

    解决这个问题使用的是Solt
    http://vuejs.org/guide/components.html#Content_Distribution_with_Slots
    http://cn.vuejs.org/guide/components.html#u4F7F_u7528_Slot__u5206_u53D1_u5185_u5BB9

    reply
    0
  • Cancelreply