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},
			]
相关推荐
重阳微噪20 分钟前
受够了空格翻页?我写了一个 Chrome 自动滚动插件,让你真正沉浸式阅读
前端
Ruihong25 分钟前
你的 Vue 3 reactive(),VuReact 会编译成什么样的 React?
vue.js·面试
Awu122727 分钟前
🍎用 pretext 搞定输入框动态宽度:一个困扰了我三天的 CSS 问题
前端
Ruihong27 分钟前
你的 Vue 3 ref(),VuReact 会编译成什么样的 React?
vue.js·面试
一 乐28 分钟前
酒店预订|基于springboot + vue酒店预订系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·酒店预订系统
萑澈28 分钟前
我用 Cloudflare 搭了一个 FlashInbox 临时邮箱
前端·next.js
慕斯fuafua33 分钟前
CSS——盒模型
前端·css
嗜好ya34 分钟前
解决 Vite 项目中 import.meta.env 变量为 undefined 的问题
前端·javascript·vue.js
Mapmost34 分钟前
Mapmost专题地图:解锁这场春游“热”
前端
心连欣36 分钟前
JS算法入门:图解“冒泡排序”,彻底搞懂双重循环的奥义
前端·javascript