作用域插槽

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

右侧打赏一下 代码改变世界一块二块也是爱
原文地址:https://www.cnblogs.com/ht955/p/14246664.html