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},
			]
相关推荐
yinuo7 小时前
前端跨页面通讯终极指南⑨:IndexedDB 用法全解析
前端
北辰alk7 小时前
Vue 动态路由完全指南:定义与参数获取详解
vue.js
北辰alk7 小时前
Vue Router 完全指南:作用与组件详解
vue.js
北辰alk7 小时前
Vue 中使用 this 的完整指南与注意事项
vue.js
xkxnq7 小时前
第二阶段:Vue 组件化开发(第 16天)
前端·javascript·vue.js
北辰alk7 小时前
Vue 插槽(Slot)完全指南:组件内容分发的艺术
vue.js
烛阴7 小时前
拒绝配置地狱!5 分钟搭建 Three.js + Parcel 完美开发环境
前端·webgl·three.js
北辰alk7 小时前
Vue 组件中访问根实例的完整指南
vue.js
北辰alk8 小时前
Vue Router 中获取路由参数的全面指南
vue.js
北辰alk8 小时前
Vue 的 v-cloak 和 v-pre 指令详解
vue.js