赞助

作用域插槽是一种特殊类型的插槽,用作一个 (能被传递数据的)可重用模板,来代替已经渲染好的元素。在子组件中,只需将数据传递到插槽,就像你将 prop 传递给组件一样

# 子组件中

Vue.component('child', {

    template: `

   <div class="child">

<slot text="我是子组件中的内容"></slot>

</div>

  `

})

 

# 父组件中

<div class="parent">

<child>

<div slot-scope="props">

<div>父组件</div>

<h3>{{ props.text }}</h3>

</div>

</child>

</div>

 

posted on 2021-01-07 15:16  Tsunami黄嵩粟  阅读(335)  评论(0编辑  收藏  举报