时间轴前后翻页

描述:日期每隔3个前后翻页

效果如下:

代码实现:

javascript 复制代码
<template>
  <div class="flex">
    <button @click="prev">前一页</button>
    <div class="box flex flex-1">
      <div class="box-item" v-for="(item, index) in mockTableFormate" :key="index">
        {{ item }}
      </div>
    </div>
    <button @click="next">后一页</button>
  </div>
</template>

<script setup>
import { computed, ref } from 'vue'
const mockTable = [
  '2024-12-1',
  '2024-12-2',
  '2024-12-3',
  '2024-12-4',
  '2024-12-5',
  '2024-12-6',
  '2024-12-7',
  '2024-12-8',
  '2024-12-9',
  '2024-12-10',
  '2024-12-11'
]

const total = mockTable.length
const currentIndex = ref(total)
const step = 3

const mockTableFormate = computed(() => {
  if (currentIndex.value >= step) {
    return mockTable.slice(currentIndex.value - step, currentIndex.value)
  } else {
    return mockTable.slice(0, currentIndex.value)
  }
})

function prev() {
  if (currentIndex.value - step > 0) {
    currentIndex.value = Math.max(currentIndex.value - step, 0)
  }
}

function next() {
  currentIndex.value = Math.min(currentIndex.value + step, total)
}
</script>

<style lang="scss" scoped>
.box {
  margin: 0 10px;
  width: 300px;
  .box-item {
    border: 1px solid red;
    border-radius: 4px;
  }
}

.flex {
  display: flex;
  justify-content: space-around;
}
</style>
相关推荐
习明然15 小时前
UniApp开发体验感受总结
前端·uni-app
AI人工智能+电脑小能手15 小时前
【大白话说Java面试题】【Java基础篇】第32题:Java的异常处理机制是什么
java·开发语言·后端·面试
刀法如飞15 小时前
Claude Code Skills 推荐:2026年最值得安装的10个AI技能
前端·后端·ai编程
阿豪只会阿巴16 小时前
【没事学点啥】TurboBlog轻量级个人博客项目——项目介绍
javascript·python·django·html
Lee川16 小时前
面试手写 KeepAlive:React 组件缓存的实现原理
前端·react.js·面试
墨染天姬16 小时前
【AI】cursor提示词小技巧
前端·数据库·人工智能
烛阴16 小时前
TEngine 入门系列(一):TEngine 是什么 & 为什么选它
前端·unity3d
转转技术团队16 小时前
WebNN:让 AI 推理在浏览器中“零距离”运行
前端
刀法如飞17 小时前
TypeScript 数组去重的 20 种实现方式,哪一种你还不知道?
前端·javascript·算法
無限進步D17 小时前
Java 面向对象高级 接口
java·开发语言