时间轴前后翻页

描述:日期每隔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>
相关推荐
是个西兰花7 分钟前
C++:异常
开发语言·c++·异常
\xin11 分钟前
pikachu自编CSRF(GET),CSRF(POST),CSRF(token)
前端·csrf
AI人工智能+电脑小能手11 分钟前
【大白话说Java面试题】【Java基础篇】第18题:HashMap底层是如何扩容的
java·开发语言·面试·散列表·hash-index·hash
是大强14 分钟前
前端一个项目用node20 一个项目用node14 怎么切换
前端
AbandonForce14 分钟前
Map类:pair键值对|map的基本操作|operator[]
开发语言·c++·算法·leetcode
澈20716 分钟前
C++核心:封装与static静态成员实战指南
开发语言·c++·算法
不老刘20 分钟前
Git Cherry-Pick:微前端架构下的“精准医疗”与最佳实践
前端·git
wuyoula33 分钟前
全新多平台电商代付商城源码
开发语言·c++·ui·小程序·php源码
玖疯子34 分钟前
IT疑难杂症诊疗室:系统性故障排查指南
开发语言·php
码云数智-大飞35 分钟前
OpCache 原理深挖:从字节码缓存到预加载(Preloading)的实战配置
java·开发语言