时间轴前后翻页

描述:日期每隔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>
相关推荐
Kiyra2 分钟前
LLM 的 JSON 不靠谱:结构化输出的重试与修复实战
开发语言·python·json
fengci.8 分钟前
CTF+随机困难部分
android·开发语言·网络·安全·php
沐风。5612 分钟前
pyton笔记
开发语言
小村儿18 分钟前
连载
前端·后端·ai编程
自不量力的A同学18 分钟前
PHP 8.5.6 发布
开发语言·php
基德爆肝c语言22 分钟前
Qt控件:按钮类
开发语言·qt
茉莉玫瑰花茶25 分钟前
LangGraph 入门教程:构建 AI 工作流 [ 案例二 ]
开发语言·人工智能·python
yaoxin52112325 分钟前
403. Java 文件操作基础 - 写入二进制文件
java·开发语言·python
爱喝水的鱼丶29 分钟前
SAP-ABAP:ABAP Development Tools(ADT)安装配置学习分享教程(四篇连载) 第二篇:ADT客户端完整安装与初始配置教程
运维·开发语言·学习·sap·abap
dinl_vin32 分钟前
LangChain 系列·(九):Agent——让 AI 自己做决策
前端·人工智能·langchain