vue实现表格轮播

bash 复制代码
<template>
  <!-- 省略其他代码 -->
  <el-col :span="7">
    <div class="mb-20">
      <div class="station_box">
        <div class="show_title"><span class="title_name">焊接设备实时信息</span></div>
        <div class="height300" style="padding: 0px 15px;">
          <div class="infotb">
            <div class="disinline_block th tbcontent">
              <div class="name p11">机器人</div>
              <div class="p11">链接状态</div>
              <div class="p11">操作模式</div>
              <div class="p11">运行状态</div>
              <div class="p6">速度倍率</div>
              <div class="p11">加工节拍</div>
            </div>
            <!-- 修改这里:只显示currentRightTbData中的数据 -->
            <div class="disinline_block tbcontent" v-for="item in currentRightTbData" :key="item.name">
              <div class="name p11">{{ item.name }}</div>
              <div class="p11">{{ item.ljzhuangtai }}</div>
              <div class="p11">{{ item.moshi }}</div>
              <div class="p11">{{ item.yxzhuangtai }}</div>
              <div class="p11">{{ item.beilv }}</div>
              <div class="p11">{{ item.jiepai }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </el-col>
  <!-- 省略其他代码 -->
</template>

<script>
export default {
  name: 'bulletinboard',
  data() {
    return {
      // 省略其他数据...
      rightTbIndex: 0, // 当前显示的起始索引
      rightTbInterval: null, // 轮播定时器
    }
  },
  computed: {
    // 计算当前要显示的表格数据(每次两条)
    currentRightTbData() {
      const start = this.rightTbIndex;
      const end = Math.min(start + 2, this.righttbdata.length);
      return this.righttbdata.slice(start, end);
    }
  },
  beforeDestroy() {
    // 清除定时器
    if (this.rightTbInterval) {
      clearInterval(this.rightTbInterval);
    }
    // 省略其他清理代码...
  },
  mounted() {
    // 初始化轮播
    this.startRightTbCarousel();
    // 省略其他初始化代码...
  },
  methods: {
    // 启动右侧表格数据轮播
   startRightTbCarousel() {
            this.rightTbInterval = setInterval(() => {
                // 计算下一次的起始索引
                const nextIndex = this.rightTbIndex + 4;
                
                // 如果下一次会超出数据范围,则回到开头
                if (nextIndex >= this.righttbdata.length) {
                    this.rightTbIndex = 0;
                } else {
                    this.rightTbIndex = nextIndex;
                }
            }, 3000); // 每3秒切换一次
        },
    // 省略其他方法...
  }
}
</script>
bash 复制代码
rightTbIndex: 0, // 当前显示的起始索引
            rightTbInterval: null, // 轮播定时器
            righttbdata:[
                {
                    "name":"A",
                    "ljzhuangtai":"联机",
                    "moshi":"自动",
                    "yxzhuangtai":'待机',
                    "beilv":"100%",
                    "jiepai":"2651.35s",
                },
                {
                    "name":"B",
                    "ljzhuangtai":"联机",
                    "moshi":"自动",
                    "yxzhuangtai":'待机',
                    "beilv":"100%",
                    "jiepai":"2651.35s",
                },
                ]
相关推荐
共享家95276 小时前
搭建 AI 聊天机器人:”我的人生我做主“
前端·javascript·css·python·pycharm·html·状态模式
摘星编程8 小时前
OpenHarmony环境下React Native:自定义useTruncate文本截断
javascript·react native·react.js
Duang007_8 小时前
【LeetCodeHot100 超详细Agent启发版本】字母异位词分组 (Group Anagrams)
开发语言·javascript·人工智能·python
有来技术8 小时前
Spring Boot 4 + Vue3 企业级多租户 SaaS:从共享 Schema 架构到商业化套餐设计
java·vue.js·spring boot·后端
东东5169 小时前
学院个人信息管理系统 (springboot+vue)
vue.js·spring boot·后端·个人开发·毕设
2601_9498683610 小时前
Flutter for OpenHarmony 电子合同签署App实战 - 主入口实现
开发语言·javascript·flutter
m0_7482299910 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
xiaoxue..10 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
摘星编程10 小时前
在OpenHarmony上用React Native:自定义useHighlight关键词高亮
javascript·react native·react.js
2601_9496130211 小时前
flutter_for_openharmony家庭药箱管理app实战+用药知识详情实现
android·javascript·flutter