el-table 嵌套封装使用

bash 复制代码
<template>
<el-table :data="data" :height="height" border @row-click="rowTab">
 	<el-table-column v-if="noIndex" type="index" align='center' width="120" label="序号"></el-table-column>
 	
    <template v-for="item in column">
        <el-table-column
            v-if="item.slot" 
            :key="item.prop" 
            :prop="item.prop" 
            :label="item.label" 
            :width="item.width"
			:align="item.align">
            <template v-slot:default="scope">   
                <slot  
                    :scope="scope" 
                    :name="item.prop"> 
                </slot>
            </template> 
        </el-table-column>
        <el-table-column
            v-else
            :key="item.prop" 
            :prop="item.prop" 
            :label="item.label" 
            :width="item.width"
            :type="item.type"
			:align="item.align">  
        </el-table-column> 
    </template> 
</el-table>
</template>

<script>
export default {
    name: '',
    props: {
        data:{
            type: Array,
            required: true,
            default() {
                return []
            }
        },
        column: {
            type: Array,
            required: true, 
            default() {
                return []
            }
        },
		height:{
			type:Number
		},
        noIndex:{
            type:Boolean,
             default() {
                return true
            }
        }
    },
    methods:{
        rowTab(row){
            this.$emit("rowClick", row);
        }
    }
}
</script>

使用

bash 复制代码
<zTable  :data="tabledata" :column="column" :height="tableHeight"  style="width: 100%">
					<template v-slot:status="{scope}">
						<p v-if="scope.row.status==1" ><span></span>有效</p>
						
					</template>
					<template v-slot:index="{scope}">
						<el-button type="primary" icon="el-icon-view" circle @click="See(scope.$index,scope.row)"></el-button>
						
					</template>
				</zTable>

参数

bash 复制代码
this.column = [
        		{prop: 'name', label: '名称',align:"center"},
				{prop: 'status', label: '状态',align:"center",slot:true,width:150},
			]
相关推荐
大雷神3 分钟前
HarmonyOS APP<玩转React>开源教程二十一:测验服务层实现
前端·react.js·开源·harmonyos
apcipot_rain4 分钟前
事无巨细地解释一个vue前端网页
前端·javascript·vue.js
han_6 分钟前
JavaScript设计模式(三):代理模式实现与应用
前端·javascript·设计模式
~欲买桂花同载酒~11 分钟前
项目安装- React + TypeScript
前端·react.js·typescript
光辉GuangHui11 分钟前
SDD 实践:OpenSpec + Superpowers 整合创建自定义工作流
前端·后端
ssshooter18 分钟前
infer,TS 类型系统的手术刀
前端·面试·typescript
用户31673613034218 分钟前
图片懒加载,我总结了三个方式
前端
灰太狼大大王20 分钟前
2026 前端基石:HTML5 全景知识体系指南(从入门到架构师思维)
前端
米丘21 分钟前
vue-router 5.x 文件式路由
前端·vue.js
始持21 分钟前
第十五讲 本地存储
前端·flutter