欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > 【无标题】

【无标题】

2025/6/16 13:15:16 来源:https://blog.csdn.net/qq_32439381/article/details/143204449  浏览:    关键词:【无标题】

前提:表格遍历列需要插入自定义格式

一、使用v-html插入,缺点是只能写简单的html

1. 组件

<!-- html插槽 --><el-table-columnv-if="item.type == 'html'":key="item.id":label="item.name":prop="item.id":show-overflow-tooltip="true":width="item.width ? item.width : ''":formatter="item.formatter"><template slot-scope="scope"><div v-html="item.html(scope.row)"></div></template></el-table-column>

2. 父组件

        {name: '体检表生成状态',id: 'pdfStatus',type: 'html',html: row => {const pdfErrorDesc = row.pdfErrorDescconst xzsj = dateFormat(new Date(row.xzsj), 'yyyy-MM-dd HH:mm:ss')switch (row.pdfStatus) {case '0':return `<div>未生成</div>`case '1':return `<div>已生成<div>${xzsj}</div></div>`case '2':return `<div>生成中</div>`case '3':return `<div>生成失败<div>${pdfErrorDesc}</div></div>`}}}

二、使用slot插槽插入,完美拒绝表格列的自定义

1. 组件

<el-table-columnv-if="item.type == 'slot'":key="item.id":label="item.name":prop="item.id":show-overflow-tooltip="true":width="item.width ? item.width : ''":formatter="item.formatter"><template slot-scope="scope"><slot :scope="scope" :name="item.slot"></slot></template></el-table-column>

 2. 父组件

        {name: '标记操作者',id: 'bjczr',type: 'slot',slot: 'bjczr'},
<template v-slot:bjczr="scope"><el-popover trigger="hover" placement="top"><p><span class="bjczr-text">用户名: </span>{{ scope.scope.row.bjczr }}</p><p><span class="bjczr-text">账号:</span> {{ scope.scope.row.bjczrYhm }}</p><p><span class="bjczr-text">所属部门:</span>{{ scope.scope.row.bjczrBmMc }}</p><div slot="reference" class="name-wrapper"><el-tag size="medium">{{ scope.scope.row.bjczr }}</el-tag></div></el-popover>
</template>

三、总结

如果只是简单的html,直接用v-html,如果是相对复杂,需要用到vue的组件,用slot。

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词