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},
			]
相关推荐
IT_陈寒25 分钟前
React状态更新那点事儿,我掉坑里爬了半天
前端·人工智能·后端
cwxcc29 分钟前
Google Core Web Vitals(核心网页指标)
前端·性能优化
|晴 天|1 小时前
Vue 3 + LocalStorage 实现博客游戏化系统:成就墙、每日签到、积分商城
前端·vue.js·游戏
逾明1 小时前
Claude Code及Codex的MCP安装和Mastergo MCP的使用
前端·mcp
LovroMance1 小时前
如何进行组件封装
前端
難釋懷2 小时前
Redis服务器端优化-慢查询优化
前端·redis·bootstrap
sghuter2 小时前
Chrome如何重塑Web标准未来
前端·chrome
渣渣xiong2 小时前
从零开始:前端转型AI agent直到就业第十四天-第十七天
前端·人工智能
changshuaihua0012 小时前
React 入门
前端·javascript·react.js
兰为鹏2 小时前
做前端需求总结出的非常好用的skill
前端