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},
			]
相关推荐
踩着两条虫10 分钟前
VTJ.PRO AI + 低代码实战:接入高德地图
前端·vue.js·ai编程
绝世唐门三哥11 分钟前
React性能优化:memo、useMemo和useCallback全解析
前端·react.js·memo
兔子零102413 分钟前
Claude Code 都把宠物养进终端了,我做了一个真正能长期玩的中文宠物游戏
前端·游戏·游戏开发
xiaotao13114 分钟前
Vite 与 Webpack 开发/打包时环境变量对比
前端·vue.js·webpack
摆烂工程师18 分钟前
教你如何查询 Codex 最新额度是多少,以及 ChatGPT Pro、Plus、Business 最新额度变化
前端·后端·ai编程
捧月华如22 分钟前
响应式设计原理与实践:适配多端设备的前端秘籍
前端·前端框架·json
笨笨狗吞噬者24 分钟前
VSCode 插件推荐 Copy Filename Pro,快速复制文件、目录和路径的首选
前端·visual studio code
Armouy26 分钟前
Electron:核心概念、性能优化与兼容问题
前端·javascript·electron
淡笑沐白37 分钟前
ECharts入门指南:数据可视化实战
前端·javascript·echarts
魔卡少女138 分钟前
Nginx配置代码化自动部署詹金斯/Github方案
前端·nginx·github