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

前言

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

element 中的自定义列表格用法

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

<template slot-scope="scope">
  <div class="overPointr2">
    {{scope.row.address}}
  </div>
</template>

完整的代码:

<el-table
  :data="tableData"
   style="width: 100%">
 <el-table-column
     type="index"
     width="50">
 </el-table-column>
 <el-table-column
     prop="name"
     label="姓名"
     min-width="120">
 </el-table-column>
 <el-table-column
     label="地址"
     min-width="300">
   <template slot-scope="scope">
     <div class="overPointr2">
       {{scope.row.address}}
     </div>
   </template>
 </el-table-column>
 <el-table-column
     label="操作"
     min-width="120">
   <template slot-scope="scope">
     <el-button
         @click.native.prevent="deleteRow(scope.$index, tableData)"
         type="text"
         size="small">
       移除
     </el-button>
   </template>
 </el-table-column>
</el-table>

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

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

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大可-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值