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},
			]
相关推荐
摆烂工程师1 小时前
(2025年11月)开发了 ChatGPT 导出聊天记录的插件,ChatGPT Free、Plus、Business、Team 等用户都可用
前端·后端·程序员
gongzemin1 小时前
使用阿里云ECS部署前端应用
前端·vue.js·后端
用户41180034153411 小时前
Flutter课题汇报
前端
环信1 小时前
实战教程|快速上线音视频通话:手把手教你实现呼叫与接听全流程
前端
Dgua1 小时前
✨TypeScript快速入门第一篇:从基础到 any、unknown、never 的实战解析
前端
用户9714171814271 小时前
前端开发中的跨域问题:Vite 开发环境配置指南
vue.js·vite
海云前端11 小时前
Vue3 大屏项目投屏功能开发:多显示器适配实践
前端
技术小丁1 小时前
使用 HTML + JavaScript 实现酒店订房日期选择器(附完整源码)
前端·javascript
hashiqimiya1 小时前
harmonyos的鸿蒙的跳转页面的部署
开发语言·前端·javascript
向日葵同志443302 小时前
使用@univerjs纯前端渲染excel, 显示图片、链接、样式
前端·react.js·excel