时间轴前后翻页

描述:日期每隔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>
相关推荐
天蓝色的鱼鱼9 分钟前
React Router v8 来了:react-router-dom 没了,老项目该怎么迁移?
前端·react.js
Bolt44 分钟前
TypeScript 7.0 来了:当 tsc 用 Go 重写之后
javascript·typescript·go
闪闪发光得欧1 小时前
前端提效新思路:Gemini 3.5 自动化定位 CSS 异常
前端·css
yingyima1 小时前
掌握正则表达式的核心:贪婪与非贪婪匹配的底层机制
前端
奇奇怪怪的1 小时前
文档摄入与 Chunking 策略全对决
前端
阳火锅2 小时前
😭测试小姐姐终于不骂我了!这个提BUG神器太香了...
前端·javascript·面试
道友可好3 小时前
AI 是最好的混乱放大器:代码熵管理实战
前端·人工智能·后端
猩猩程序员3 小时前
前端学习 AI Agent 开发
前端
Younglina4 小时前
打了3年羽毛球球才发现:我对自己的装备和胜率一无所知
前端·后端
风骏时光牛马4 小时前
Bash脚本高阶实战与常见报错完整代码案例详解
前端