时间轴前后翻页

描述:日期每隔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>
相关推荐
西洼工作室4 分钟前
UniApp云开发笔记
前端·笔记·uni-app
yoyo_zzm7 分钟前
汇编到PHP:五大编程语言核心特性全解析
开发语言·汇编·php
zhangxingchao10 分钟前
AI应用开发一: AI 编程、大模型调用和 Agent
前端·人工智能·后端
.ZGR.15 分钟前
线程池相关知识及并发统计案例实现
java·开发语言
流年如夢17 分钟前
初入C++
开发语言·c++
zzzsde19 分钟前
【Linux】线程同步和互斥(1):线程互斥与加锁实现
linux·运维·服务器·开发语言·算法
yoyo_zzm19 分钟前
编程语言大比拼:C++到PHP全解析
开发语言·c++·php
努力努力再努力wz26 分钟前
【C++高阶数据结构系列】:时间轮定时器详解:原理分析与代码实现,带你从零手撕时间轮!(附时间轮的实现源码)
c语言·开发语言·数据结构·c++·qt·算法·ui
ljt272496066129 分钟前
Vue笔记(三)--用户交互
javascript·vue.js·笔记
颖火虫盟主31 分钟前
Hello World MCP Server 实现总结
java·前端·python