vue3表格循环滚动

依赖安装

"vue3-seamless-scroll": "^2.0.1",
import vue3SeamlessScroll from "vue3-seamless-scroll";

app.use(vue3SeamlessScroll)

注意:还需要安装elementplus

使用

<template>
  <div class="card_box">
    <el-table
        ref="reportTable"
        :data="tableData"
        style="width: 100%"
        height="170"
        size="small"
        :header-cell-style="{ background: 'rgb(2 40 58)', color: '#fff' }"
        :row-style="rowstyle"
    >
      <el-table-column prop="deviceCode" label="设备编号" />
      <el-table-column prop="alarmContent" label="告警内容" />
      <el-table-column prop="alarmTime" label="告警时间" />
    </el-table>
  </div>
</template>

<script setup lang="ts" name="righ3">
let tableData: any = ref([
  {
    deviceCode: '123456789',
    alarmContent: '张三',
    alarmTime: '2023-05-01'
  },
  {
    deviceCode: '123456789',
    alarmContent: '张三',
    alarmTime: '2023-05-01'
  },  {
    deviceCode: '123456789',
    alarmContent: '张三',
    alarmTime: '2023-05-01'
  },  {
    deviceCode: '123456789',
    alarmContent: '张三',
    alarmTime: '2023-05-01'
  },  {
    deviceCode: '123456789',
    alarmContent: '张三',
    alarmTime: '2023-05-01'
  },
])

const reportTable = ref()
function scrollUp() {
  nextTick(() => {
    const demo = reportTable.value?.$refs.bodyWrapper.getElementsByClassName('el-scrollbar__wrap')[0] as HTMLElement
    if (!demo) return
    const tableScroll = ref(true)
    demo.addEventListener('mouseover', () => {
      tableScroll.value = false
    })
    demo.addEventListener('mouseout', () => {
      tableScroll.value = true
    })
    setInterval(() => {
      if (tableScroll.value) {
        demo.scrollTop += 1
        if (demo.scrollTop + demo.clientHeight >= demo.scrollHeight) {
          demo.scrollTop = 0
        }
      }
    }, 100)
  })
}


const rowstyle = ({ row, rowIndex }) => {
  if (rowIndex % 2 === 0) {
    return {
      backgroundColor: 'rgba(3, 76, 106, 1)',
    }
  }
}

onMounted(() => {
  scrollUp()
})

</script>
<style scoped lang="scss">
.card_box {
  width: 100%;
  height: 100%;
  background: rgba(135, 206, 250, 0.15);
  border-radius: 4px;
}

/*设置table的透明色*/
.el-table {
  --el-table-border-color: transparent;
  --el-table-border: none;
  --el-table-text-color: #bdbdbe;
  --el-table-header-text-color: #bdbdbe;
  --el-table-row-hover-bg-color: transparent;
  --el-table-current-row-bg-color: transparent;
  --el-table-header-bg-color: transparent;
  --el-table-bg-color: transparent;
  --el-table-tr-bg-color: transparent;
  --el-table-expanded-cell-bg-color: transparent;
}
</style>

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值