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},
			]
相关推荐
岱宗夫up8 小时前
FastAPI入门(上篇):快速构建高性能Python Web API
开发语言·前端·python·fastapi
紫陌涵光9 小时前
112. 路径总和
java·前端·算法
漠月瑾-西安9 小时前
CVE-2025-55182漏洞解析:你的React项目安全吗?
前端·安全·react.js
No丶slovenly9 小时前
flutter笔记-输入框
前端·笔记·flutter
国产化创客10 小时前
ESP32+Web实现智能气象站
前端·物联网·智能家居·智能硬件
coderYYY11 小时前
VSCode终端启动报错
前端·ide·vscode·npm·编辑器
tod11311 小时前
Redis 数据类型与 C++ 客户端实践指南(redis-plus-plus)
前端·c++·redis·bootstrap·html
Sylvia33.11 小时前
火星数据:棒球数据API
java·前端·人工智能
weixin1997010801611 小时前
1688商品详情页前端性能优化实战
前端·性能优化
DEMO派12 小时前
前端常用XSS攻击演示与防御方案解析
前端·xss