• element-ui和element-plus的自定义列表格用法


    前言

     element-plus 这个 UI 组件库,虽说基本和 vue2 + element-ui 差不多,但还是有点区别,以至于按emenent-ui的写法来写会发现报错,下面我将讲解一下element-ui和element-plus的自定义表格的用法

    element 中的自定义列表格用法

    自定义列时只需要声明 slot-scope="scope" 即可。自定义内容需要使用数据时只需要使用 scope.row 即可获取该行数据。

    1. <template slot-scope="scope">
    2. <div class="overPointr2">
    3. {{scope.row.address}}
    4. </div>
    5. </template>

    完整的代码:

    1. <el-table
    2. :data="tableData"
    3. style="width: 100%">
    4. <el-table-column
    5. type="index"
    6. width="50">
    7. </el-table-column>
    8. <el-table-column
    9. prop="name"
    10. label="姓名"
    11. min-width="120">
    12. </el-table-column>
    13. <el-table-column
    14. label="地址"
    15. min-width="300">
    16. <template slot-scope="scope">
    17. <div class="overPointr2">
    18. {{scope.row.address}}
    19. </div>
    20. </template>
    21. </el-table-column>
    22. <el-table-column
    23. label="操作"
    24. min-width="120">
    25. <template slot-scope="scope">
    26. <el-button
    27. @click.native.prevent="deleteRow(scope.$index, tableData)"
    28. type="text"
    29. size="small">
    30. 移除
    31. </el-button>
    32. </template>
    33. </el-table-column>
    34. </el-table>

    element-plus 中的自定义列表格用法

    跟 element 差不多,只不过不再是声明 slot-scope="scope",而是按需声明 #default 或者 #default="scope"

    • 自定义内容需要使用该行数据时,声明 #default="scope",再通过 scpoe.row 获取数据。
    1. <el-table-column
    2. fixed="right"
    3. label="操作"
    4. width="100">
    5. <template #default="scope">
    6. <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
    7. <el-button type="text" size="small">编辑</el-button>
    8. </template>
    9. </el-table-column>
    • 自定义内容需要使用该行数据时,声明 v-slot:default="scope",再通过 scpoe.row 获取数据。
    1. <el-table-column label="操作" align="center">
    2. <template v-if="true" v-slot:default="scope">
    3. <el-button type="primary" size="small" @click="bj"><el-icon><Edit /></el-icon> <span style="margin-left: 3px">编辑</span></el-button>
    4. <el-button type="danger" size="small" @click="sc(scope.row)"><el-icon><Delete /></el-icon> <span style="margin-left: 3px">删除</span></el-button>
    5. </template>
    6. </el-table-column>

  • 相关阅读:
    QMetaType和QVariant使用
    关于mysql自增列起始值与数据实际id不一致的问题
    详解使用sklearn实现一元线性回归和多元线性回归
    python渗透测试入门——基础的网络编程工具
    驱动开发:STM32F7控制AD5663模拟量输出
    XSSFWorkbook Excel导出导入
    邀好友一起刷算法之合并两个有序链表
    如何在云服务器上部署 Servlet 项目
    数据分析师入门: 数据分析可视化入门知识点
    编程实例:多人同时计时计费管理系统软件,可适用于钓场计时等管理
  • 原文地址:https://blog.csdn.net/m0_55333789/article/details/132888272