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},
			]
相关推荐
前端小巷子19 分钟前
Vue 2 渲染链路剖析
前端·vue.js·面试
Mintopia40 分钟前
🧠 AI 本地自由之路:Ollama 教程指南
前端·javascript·aigc
Mintopia1 小时前
🧠 从像素到现实:用 Three.js + Cesium 构建数字孪生系统
前端·javascript·three.js
xyphf_和派孔明1 小时前
关于Web前端安全防御CSRF攻防的几点考虑
前端·安全·csrf
stars1 小时前
数字人开发02--前端服务配置
前端·人工智能
懋学的前端攻城狮2 小时前
Next.js + TypeScript + Shadcn UI:构建高性能懒加载与无限滚动系统
前端·react.js·前端框架
宋辰月2 小时前
Vue2的进阶Vue3
前端·javascript·vue.js
酷飞飞3 小时前
C语言的复合类型、内存管理、综合案例
java·c语言·前端
姜太小白4 小时前
【前端】CSS Grid布局介绍及示例
前端·css
风继续吹..7 小时前
后台管理系统权限管理:前端实现详解
前端·vue