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},
			]
相关推荐
kyriewen1 分钟前
重排、重绘、合成:浏览器渲染的“三兄弟”,你惹不起也躲不过
前端·javascript·浏览器
NickJiangDev6 分钟前
Elpis-Core 技术解析:从零构建一个基于 Koa 的企业级 Node.js 框架内核
前端
我要让全世界知道我很低调7 分钟前
来聊聊 Codex 高效编程的正确姿势
前端·程序员
NickJiangDev8 分钟前
Elpis Webpack 工程化实战:Vue 多页应用的构建体系搭建
前端
米饭同学i9 分钟前
GitLab CI/CD + Vue 前端 完整方案
前端
yuki_uix11 分钟前
遇到前端题目,我现在会先问自己这四个问题
前端·面试
Wect12 分钟前
JS 手撕:对象创建、继承全解析
前端·javascript·面试
PeterMap16 分钟前
Vue.js全面解析:从入门到上手,前端新手的首选框架
前端·vue.js
3秒一个大17 分钟前
深入理解 JS 中的栈与堆:从内存模型到数据结构,再谈内存泄漏
前端·javascript·数据结构
weixin_4138385618 分钟前
基于区块链的校园二手书交易系统
vue.js·spring·区块链·fabric