最近是搭建新的框架,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更加简练,其他很多更高级的用法我还没去研究,目前只用到我在项目中能用到的。
本文地址:https://blog.csdn.net/qq_27175079/article/details/108574421
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论