时间轴前后翻页

描述:日期每隔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>
相关推荐
用户440281827807几秒前
我用 TRAE 一晚上从零撸了个微信投票小程序: 17 个云函数 + 11 个页面的全链路实战
前端
BullSmall3 分钟前
SonarQube 9.9.8-community 适配 Jenkins 版本说明
java·前端·jenkins
tryCbest5 分钟前
第一篇:HTML5 核心知识全解 + 项目起步
前端·html·html5
Soari7 分钟前
交换机转发模式
开发语言·网络·php
百度一下吧12 分钟前
CSS 伪类使用与实践:从入门到进阶
前端·css
hunterandroid13 分钟前
android方案 : Multiplatform 跨平台开发实战:一套代码,多端运行
android·前端
百度一下吧17 分钟前
CSS3 之后新增的特性:从 CSS4 到现代 CSS 的演进
前端·css·css3
deviant-ART17 分钟前
Java 并发编程:深入理解 synchronized 的使用与原理
java·开发语言·后端
爱喝热水的呀哈喽22 分钟前
hm探查。
java·前端·人工智能