时间轴前后翻页

描述:日期每隔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>
相关推荐
R_.L3 分钟前
【QT】常用控件(按钮类控件、显示类控件、输入类控件、多元素控件、容器类控件、布局管理器)
开发语言·qt
C澒4 分钟前
前端分层架构实战:DDD 与 Clean Architecture 在大型业务系统中的落地路径与项目实践
前端·架构·系统架构·前端框架
BestSongC8 分钟前
行人摔倒检测系统 - 前端文档(1)
前端·人工智能·目标检测
Zach_yuan12 分钟前
自定义协议:实现网络计算器
linux·服务器·开发语言·网络
云姜.18 分钟前
java多态
java·开发语言·c++
CoderCodingNo27 分钟前
【GESP】C++五级练习题 luogu-P1865 A % B Problem
开发语言·c++·算法
陳103034 分钟前
C++:红黑树
开发语言·c++
一切尽在,你来39 分钟前
C++ 零基础教程 - 第 6 讲 常用运算符教程
开发语言·c++
泉-java41 分钟前
第56条:为所有导出的API元素编写文档注释 《Effective Java》
java·开发语言
0思必得041 分钟前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化