时间轴前后翻页

描述:日期每隔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>
相关推荐
前端缘梦2 分钟前
Next.js 实现AI流式输出(打字机效果)
前端·面试·全栈
oscar9992 分钟前
给 Claude Code 装上浏览器:Chrome 集成测试版详解
前端·chrome·集成测试·浏览器
美团内卖3 分钟前
雪碧图还在手写 background-position?试试这款 Vite + Vue3 构建期雪碧图插件
前端
大萝卜呼呼4 分钟前
Next.js第三课 - 布局与页面 - 优栈
前端·next.js
码云数智-园园5 分钟前
Java接口与抽象类:从设计哲学到应用场景的深度辨析
前端
莱昂晨5 分钟前
Vue 3偶发字体乱码 - 原因探究
前端·javascript·vue.js
AlkaidSTART5 分钟前
0 基础入门 Zustand:新手友好的 React 状态管理方案
前端·javascript
云天0016 分钟前
前端私活神器,nodejs+vue3+typescript全栈框架,
前端·后端·node.js
我命由我123458 分钟前
HTML 开发 - HTML 描述列表标签(<dl>、<dt>、<dd>)
前端·javascript·css·html·css3·html5·js
csdn2015_10 分钟前
Set<String> 类型取第一条记录
开发语言·windows·python