doubleyong
管理员
管理员
  • 最后登录2026-05-10
  • 发帖数1198
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:6690回复:0

[Vue]Vue插槽:(2.6.0以后版本弃用slot和slot-scope,改用v-slot)

楼主#
更多 发布于:2019-07-05 22:01
Vue插槽:(2.6.0以后版本弃用slot和slot-scope,改用v-slot)


关于Vue插槽的概念,大家可以从vue官网的api查看,我是看到网站的对于初接触 这个要概念的人来说不是很清楚,我来贴下原码,就比较直观了
贴下原码:
具名插槽:v-slot:header
Html:
<div id=’app’>
   <child>
       <template v-slot:header>
          <div>this is a header</div>
</template>
</child>
</div>
script部分:
Vue.component(‘child’,{
 Template:’<div><slot name=’header’></slot></div>
}
作用域插槽
Html:
<div id=’app’>
   <child>
       <template v-slot=’list’>
          <div>pw_list.item</div>
</template>
</child>
</div>
script部分:
Vue.component(‘child’,{
data:function(){
 return{
     list:[1,2,3,4,5,6]
}
}
,
 Template:’<div><slot v-for=”item of list” :item=item></slot></div>
}



参考:https://www.cnblogs.com/adah/p/10449787.html
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号