时间轴前后翻页

描述:日期每隔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>
相关推荐
Gofarlic_oms14 分钟前
Allegro高级功能模块许可证管理注意事项
运维·服务器·开发语言·matlab·负载均衡
启山智软7 分钟前
前沿主流技术栈商城系统(Java JDK21 + Vue3 + Uniapp)
java·开发语言·uni-app
明月_清风14 分钟前
Nginx 生产环境配置完全指南:从安全加固到性能调优
前端·nginx
用户6000718191016 分钟前
【翻译】用 Reanimated CSS 动画为 TextInput 添加发光效果
前端
李剑一22 分钟前
前后端命名冲突?驼峰与下划线的统一方案(附可直接复用代码)
前端
QH1392923188022 分钟前
Rohde & Schwarz ZNA43矢量网络分析仪的使用方法
开发语言·php
用户114818678948425 分钟前
Git Stash 丢失后的完整找回指南
前端·git
代码不加糖26 分钟前
2026 React 面试“通关秘籍”:高频 12 问 + 深度解析(含Hooks源码思想)
前端·react.js·面试
沐知全栈开发26 分钟前
SVG 实例
开发语言
我滴老baby27 分钟前
ReAct推理模式详解让智能体学会边思考边行动
前端·react.js·前端框架