vue3+antd/arcod实现列表中每一行根据不同数据添加不同的样式

前言:

        arco design/antd中实现一个需求,列表的每一行都要有自己不同的样式,根据不同的数据,下面分享实现这个效果的方法。

实现效果:

实现方法:

1、arco design

1)定义方法
const rowClassName = (record, index) =>{
  let className = '';
  if (record?.status === 11) {
    className = 'firstJoinClass';
  }else if(record?.status === 21){
    className = 'mrJoinClass';
  }
  return className;
}
2)列表中添加
<a-table :row-class="rowClassName" 
...
api:
row-class表格行元素的类名。2.34.0 版本增加函数值支持string| any[]| Record<string, any>| ((record: TableData, rowIndex: number) => any)-2.16.0

2、antd

 1)定义方法
const rowClassName = (record, index) =>{
  let className = '';
  if (record?.status === 11) {
    className = 'firstJoinClass';
  }else if(record?.status === 21){
    className = 'mrJoinClass';
  }
  return className;
}
2)列表中添加
<a-table :rowClassName="rowClassName" 
...

api:

rowClassName表格行的类名Function(record, index):string-
  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是一个简单的示例代码,基于Vue2,antd和sortablejs实现了表格的拖拽功能。 ```html <template> <div> <h2>表格1</h2> <table> <thead> <tr> <th>姓名</th> <th>年龄</th> </tr> </thead> <tbody v-sortable="{onEnd: onEnd1}"> <tr v-for="(item, index) in list1" :key="item.id"> <td>{{ item.name }}</td> <td>{{ item.age }}</td> </tr> </tbody> </table> <h2>表格2</h2> <table> <thead> <tr> <th>姓名</th> <th>年龄</th> </tr> </thead> <tbody v-sortable="{onEnd: onEnd2}"> <tr v-for="(item, index) in list2" :key="item.id"> <td>{{ item.name }}</td> <td>{{ item.age }}</td> </tr> </tbody> </table> </div> </template> <script> import Sortable from 'sortablejs' export default { data() { return { list1: [ { id: 1, name: '张三', age: 18 }, { id: 2, name: '李四', age: 20 }, { id: 3, name: '王五', age: 22 }, ], list2: [], } }, mounted() { // 表格1和表格2都可以拖拽到另一个表格 Sortable.create(this.$el.querySelector('tbody'), { group: 'table', animation: 150, fallbackOnBody: true, swapThreshold: 0.65, }) }, methods: { onEnd1(evt) { if (evt.newIndex !== undefined) { // 从表格1拖拽到表格2 this.list2.push(this.list1.splice(evt.oldIndex, 1)[0]) } }, onEnd2(evt) { if (evt.newIndex !== undefined) { // 从表格2拖拽到表格1 this.list1.push(this.list2.splice(evt.oldIndex, 1)[0]) } }, }, } </script> ``` 在此示例,我们使用了Vue的v-sortable指令来绑定Sortable实例。在mounted钩子函数,我们为两个表格的tbody元素创建了Sortable实例,并将它们分组为“table”。然后,我们分别在onEnd1和onEnd2方法处理拖拽完成事件,并将拖拽的数据从一个表格移动到另一个表格。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

浩星

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

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

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

打赏作者

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

抵扣说明:

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

余额充值