vue 的slot分发内容 (多个分发)

 组件模板-元素可以用一个特殊的属性 name 来配置如何分发内容。多个 slot 可以有不同的名字。具名 slot 将匹配内容片段中有对应 slot 特性的元素

<style media="screen">
    .panel{
      margin:10px;width:150px;
      border:1px solid #ccc
    }
    .panel-header,.panel-bottom{
      height: 20px;
      background-color:antiquewhite;
    }
    .panel-body{
      min-height: 50px;
    }
  </style>

<div class="app">
    <!--多个slot分发内容 v-for遍历-->
     <panel2 v-for="item in list">
       <h2 slot="title">{{item.title}}</h2>
       <p slot="desc">{{item.desc}}</p>
       <span slot="tims">{{item.tims}}</span>
     </panel2>
  </div>
<!--组件模板-->
<script type="text/x-Template" id="panelTpl">
   <div class="panel">
       <div class="panel-header"><slot name="title"></slot></div>
       <div class="panel-body">
         <slot name="desc"></slot>
       </div>
       <div class="panel-bottom"><slot name="tims"></slot></div>
   </div>
</script>
<script type="text/javascript">
var panelTpl={
  template:'#panelTpl'
}
var vm=new Vue({
  el:'.app',
  components:{//注册组件
    "panel2":panelTpl
  },
  data:{
    list:[
      {title:'新闻一标题',desc:'一的描述',tims:'2018-07-19'},
      {title:'新闻二标题',desc:'二的描述',tims:'2018-07-18'},
      {title:'新闻三标题',desc:'三的描述',tims:'2018-07-17'}
    ]
  }

});
</script>

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑色咖啡 Ken

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值