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},
			]
相关推荐
浪客川2 分钟前
【百例RUST - 007】结构体
java·前端·rust
美狐美颜sdk6 分钟前
视频平台如何实现实时美颜?Android/iOS直播APP美颜SDK接入指南
android·前端·人工智能·ios·音视频·第三方美颜sdk·视频美颜sdk
ZHENGZJM9 分钟前
前端流式通信 Hook:useBlogStream 详解
前端·全栈开发
人道领域10 分钟前
【黑马点评日记02】Redis解决Tomcat集群Session共享问题
java·前端·后端·架构·tomcat·firefox
MRDONG111 分钟前
从 Prompt 到智能体:深入理解 APE、Active-Prompt、DSP、PAL、ReAct 与 Reflexion
前端·react.js·prompt
翻斗包菜15 分钟前
实战:使用 HAProxy 搭建高可用 Web 负载均衡集群
运维·前端·负载均衡
凯强同学20 分钟前
不上班,想裸辞,可以不可以?
服务器·前端·javascript
吹个口哨写代码20 分钟前
h5/小程序直接读本地/在线的json文件数据
前端·小程序·json
和科比合砍81分21 分钟前
【无标题】
前端
Z_Wonderful21 分钟前
Qiankun 微前端(React+Vue)基础速通webpack
前端·vue.js·react.js