阅读 592

vue 实现树形表格 + 展开收起 + tooltip气泡悬浮提示 + 文字内容超出显示溢出

前言:项目中有的需求,需要在表格中展示树形结构,官网阐述的不是很清晰明了,毕竟不是实战,废话不多少,直接上代码

效果图:

image.png

接口数据结构:

1635840580(1).jpg

DOM结构:

<el-table cell-style="padding:0" :data="treeData" row-key="id" lazy :load="load" :tree-props="{children: 'zzChildren'}">
      <el-table-column show-overflow-tooltip prop="name" :label="$t('appsSecond.item_name')"></el-table-column>
      <el-table-column prop="authRoleCount" label="已授权校色" width="100">
        <template slot-scope="scope">
          <div style="width: 100%;cursor:pointer" @click="openInfoDrawer(scope.row,'role')">
            <span >{{ scope.row.authRoleCount }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="authAccountCount" label="已授权账号" width="170">
        <template slot-scope="scope">
          <div style="width: 100%;cursor:pointer" @click="openInfoDrawer(scope.row,'account')">
            <span >{{ scope.row.authAccountCount }}</span>
          </div>
        </template>
      </el-table-column>
    </el-table>复制代码

js结构:

export default {
    data() {
        return {
            treeData: []

        }
    },
    created() {
        this.getInit()
    },
    methoods: {
        getInit() {
            this.treeData = []
            api().then((res) => {
                this.treeData = res.data.data.data.data
                if (this.treeData) {
                    this.initTree(this.treeData)
                }
            })
        },
        initTree(treeData) {
            treeData.forEach(item => {
                item.hasChildren = !item.leaf
            })
        },
        load(row, treeNode, resolve) {
            api().then((res) => {
                let childrenData = res.data.data
                this.initTree(childrenData)
                resolve(childrenData)
            })
        },
    }


作者:bug爱好者
链接:https://juejin.cn/post/7025881693328244773

文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐