时间轴前后翻页

描述:日期每隔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>
相关推荐
郝学胜-神的一滴28 分钟前
当AI遇见架构:Vibe Coding时代的设计模式复兴
开发语言·数据结构·人工智能·算法·设计模式·架构
阿里嘎多学长5 小时前
2026-02-16 GitHub 热点项目精选
开发语言·程序员·github·代码托管
芭拉拉小魔仙6 小时前
企业级Vue项目的状态管理:从原理到实战架构
前端·vue.js·架构
恋猫de小郭6 小时前
丰田正在使用 Flutter 开发游戏引擎 Fluorite
android·前端·flutter
扶苏10026 小时前
Vue 3 响应式原理深度解析
前端·javascript·vue.js
啊吧怪不啊吧6 小时前
C++之基于正倒排索引的Boost搜索引擎项目usuallytool部分代码及详解
开发语言·c++·搜索引擎·项目
NEXT066 小时前
React 性能优化:图片懒加载
前端·react.js·面试
PineappleCoder7 小时前
别让字体拖了后腿:FOIT/FOUT 深度解析与字体加载优化全攻略
前端·性能优化
CeshirenTester7 小时前
9B 上端侧:多模态实时对话,难点其实在“流”
开发语言·人工智能·python·prompt·测试用例
发现你走远了7 小时前
Windows 下手动安装java JDK 21 并配置环境变量(详细记录)
java·开发语言·windows