Vue 2.6版本后的动态插槽

最近是搭建新的框架,vue的版本比较新,旧的语法便不想再使用了,其中在插槽是还是费了一点时间的。
期望:根据字段批量生成插槽供主页自定义。
问题:静态的可以显示出来,动态的显示不出来。

最终的代码如下

//子组件 tableColumnList是table组件内部的静态插槽名称
<template v-slot:tableColumnList>
    <el-table-column
        v-for="(item, key) in tableObj.params"
        :key="key"
        :label="item.label"
        :width="item.width"
        :align="item.align || 'center'"
      >
        <template scope="scope">
          {{ item.isSolt }}
          <slot
            :name="item.prop"
            :$index="scope.$index"
            :row="scope.row"
            v-if="item.isSlot"
          ></slot>
          <span v-else>{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
    </template>
//父组件调用方法
<template v-slot:workTypeStr="{ row }">
  {{ row.workTypeStr }}
</template>

总结:新的语法使用起来会比slot-scope更加简练,其他很多更高级的用法我还没去研究,目前只用到我在项目中能用到的。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值