element树形表格动态表头(附带删除)

描述问题 树形表格无法动态添加表头
我们要的效果是这样的
在这里插入图片描述
创建treeTable 页面(组件)

<template>
    <div>
        <el-table
            :data="tableData1"
            style="width: 100%"
            row-key="id"
            lazy
            :load="load"
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
            <af-table-column
                :key="index"
                v-for="(col,index) in cols"
                :prop="col.prop" :label="col.label">
            </af-table-column>
            <el-table-column :label="label"  width="200px">
                <template slot-scope="scope">
                    <slot name="bth_" :scope="scope">
                    </slot>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
export default {
        props:{
            cols:"",
            tableData1:"",
            label:""
        }
}
</script>
<style type="text/css">
.icon-file {
    padding-right: 7px;
    padding-left: 18px
}

.icon-folder,
.icon-folder-open {
    padding-left: 7px;
    padding-right: 7px
}
</style>

B页面使用
先引入

import treeTable  from "@/treeTable "
<template>
    <div class="grade">
        <!--        表格内容-->
        //:cols="cols " :tableData1="tableData1" :label="label"这些都是用来传递数据的,组件传值,要是看不懂可以去学习一下组件传值
        <treeTable :cols="cols " :tableData1="tableData1" :label="label">
        //这块是插槽的传递,把下面按钮传递过去
        //"{scope}"是用来接收表格的id用来删除表格行 ,看不懂这块的可以去看一下我之前文章的讲解
            <template v-slot:bth_="{scope}">
                <el-button size="mini" type="primary">修改</el-button>
                <el-button type="danger" size="mini" @click="Del(scope)">删除</el-button>
            </template>
        </treeTable>
    </div>
</template>
<script>

import treeTable from "@/treeTable "

export default {
    components: {
       treeTable 
    },
    methods: {
   //删除方法,通过插槽来删除(目前只能删除一级菜单)
        Del(scope) {
            this.tableData1.splice(scope.row.id-1, 1)
        },
    },
    data() {
        return {
            cols: [
            //label里面添加表头的内容,prop里面的内容要和tableData1的键相对应来绑定数据
                {prop: 'grade', label: '类型编码'},
                {prop: 'big_time', label: ''},
                {prop: 'temperature', label: ''},
                {prop: 'wait', label: ''},
                {prop: 'bake_time', label: ''},
                {prop: 'unit', label: ''},
                {prop: 'time', label: ''},
                {prop: 'end_user', label: ''},
                {prop: 'end_time', label: ''},
            ],
            // id是为了添加删除方法
            tableData1: [{
                id: 1,
                grade: 'NL20202105362',
                big_time: "200",
                temperature: "",
                wait: "",
                bake_time: "",
                unit: "user",
                time: "2020-11-30 12:15:54",
                end_user:"user",
                end_time:"2020-10-15",
                children: [{
                    id: 31,
                    grade: 'NL20202105362',
                    big_time: "200",
                    temperature: "",
                    wait: "",
                    bake_time: "",
                    unit: "user",
                    time: "2020-11-30 12:15:54",
                    end_user:"user",
                    end_time:"2020-10-15",
                }, {
                    id: 32,
                    grade: 'NL20202105362',
                    big_time: "200",
                    temperature: "",
                    wait: "",
                    bake_time: "",
                    unit: "user",
                    time: "2020-11-30 12:15:54",
                    end_user:"user",
                    end_time:"2020-10-15",
                }]
            }, {
                id: 2,
                grade: 'NL20202105362',
                big_time: "200",
                temperature: "",
                wait: "",
                bake_time: "",
                unit: "user",
                time: "2020-11-30 12:15:54",
                end_user:"user",
                end_time:"2020-10-15",
            }, {
                id: 3,
                grade: 'NL2222222222222',
                big_time: "200",
                temperature: "",
                wait: "",
                bake_time: "",
                unit: "user",
                time: "2020-11-30 12:15:54",
                end_user:"user",
                end_time:"2020-10-15",
            }, {
                id: 4,
                grade: 'NL1111111111111',
                big_time: "200",
                temperature: "",
                wait: "",
                bake_time: "",
                unit: "user",
                time: "2020-11-30 12:15:54",
                end_user:"user",
                end_time:"2020-10-15",
            }]
        }
        }
    }

</script>


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值