时间轴前后翻页

描述:日期每隔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>
相关推荐
醉逍遥neo2 分钟前
mac新电脑-前端开发配置
前端·macos·ghostty
ZGi.ai24 分钟前
私有化大模型接入企业系统:SSO+权限+API网关完整方案
java·开发语言·大模型·私有化部署·sso·企业架构
白嫖叫上我33 分钟前
Vue3封装主题色完善版
前端
一念春风33 分钟前
记事本(C#)
开发语言·c#
a11177634 分钟前
细胞结构实验室(react 开源)
前端·javascript·开源·html
aaaak_35 分钟前
PDD 直播间 评论 , wss hex Protobuf 解析流程分析学习
java·前端·学习
fox_lht41 分钟前
第十二章 泛型、接口和生命周期
开发语言·后端·rust
ikoala41 分钟前
用了几周明基 RD280UG,我终于明白程序员为什么需要一台“专用显示器”
前端·后端·程序员
jayson.h43 分钟前
正则表达式:从文件名提取器件编号
开发语言·python·正则表达式
Dxy123931021644 分钟前
JS如何获取元素高度
开发语言·javascript·ecmascript