时间轴前后翻页

描述:日期每隔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>
相关推荐
Hello.Reader几秒前
Nuxt 4.2 + Tauri 2 接入指南把 Vue 元框架“静态化”后装进桌面/移动端
前端·javascript·vue.js
独隅几秒前
macOS 查看与安装 Java JDK 全面指南(2026年版)
java·开发语言·macos
独自破碎E4 分钟前
BISHI75 阶幂
android·java·开发语言
pas1367 分钟前
47-mini-vue 升级monorepo管理项目
前端·javascript·vue.js
浮桥9 分钟前
uniapp + h5 -- 简易抽奖转盘组件(文字版)
前端·javascript·uni-app
卓越软件开发10 分钟前
毕设全栈开发一条龙:Java/SpringBoot/Vue/ 小程序 / Python / 安卓 / AI 图像识别 人脸检测 车牌识别 YOLO
开发语言·spring boot·python·yolo·小程序·毕业设计·课程设计
一叶之秋141214 分钟前
千面之法: 释放 C++ 多态的灵活威力
开发语言·c++
柒.梧.15 分钟前
Java拷贝精讲:彻底分清浅拷贝与深拷贝
java·开发语言·python
Swift社区15 分钟前
Flutter 中如何优雅地处理复杂表单
前端·flutter·前端框架
这是个栗子17 分钟前
前端开发中的常用工具函数(三)
前端·javascript·charat