Vue2时间轴(Timeline)

简介: 本文介绍了一个基于 Vue3 的时间轴组件 `Timeline`,允许用户自定义时间轴宽度和描述文本。通过在 `Timeline.vue` 中使用模板、脚本及样式代码,文章展示了如何创建并使用该组件,并提供了示例代码以供参考。

自定义设置时间轴的宽度(width)和描述文本

效果图如下:

①创建时间轴组件Timeline.vue:

<template>
  <div class="m-timeline-area" :style="`width: ${width}px`">
    <div class="m-timeline">
      <div
        :class="['m-timeline-item', {'last': index === timelineDesc.length - 1}]"
        v-for="(desc, index) in timelineDesc"
        :key="index">
        <div class="u-tail"></div>
        <div class="u-dot"></div>
        <div class="u-content">{
  { desc || '--' }}</div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Timeline',
  props: {
    timelineDesc: { // 时间轴内容数组
      type: Array,
      default: () => {
        return []
      }
    },
    width: { // 时间轴区域总宽度
      type: Number,
      default: 360
    }
  }
}
</script>
<style lang="less" scoped>
@blue: #1890ff;
@green: #52c41a;
@red: #f5222d;
@gray: rgba(0,0,0,.25);
.m-timeline-area {
  margin: 0 auto;
  .m-timeline {
    .m-timeline-item {
      position: relative;
      padding-bottom: 30px;
      .u-tail {
        position: absolute;
        top: 10px;
        left: 5px;
        height: calc(100% - 10px);
        border-left: 2px solid #e8e8e8; // 实线
        // border-left: 2px dotted #e8e8e8; // 点线
        // border-left: 2px dashed #e8e8e8; // 虚线
      }
      .u-dot {
        position: absolute;
        width: 8px;
        height: 8px;
        border: 2px solid @blue;
        border-radius: 50%;
      }
      .u-content {
        position: relative;
        top: -6px;
        margin-left: 25px;
        word-break: break-all;
        word-wrap: break-word;
        line-height: 24px;
      }
    }
    .last {
      .u-tail {
        display: none;
      }
    }
  }
}
</style>

②在要使用的页面引入:

<Timeline :timelineDesc="timelineDesc" :width="480" />
import Timeline from '@/components/Timeline'
components: {
    Timeline
}
timelineDesc: ['Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.', 'Create a services site', 'Create a services site', 'Create a services site', 'Create a services site']
相关文章
Springboot+JPA+Sqlite整合demo
Springboot+JPA+Sqlite整合demo
844 0
uniapp 全局数据(globalData)的设置,获取,更改
uniapp 全局数据(globalData)的设置,获取,更改
3947 0
Echarts实战案例代码(26):折线图组件连接空数据connectNulls的用法
Echarts实战案例代码(26):折线图组件连接空数据connectNulls的用法
1368 0
Vue2时间轴(横向)
该横向时间轴组件 `HorizonTimeLine` 可自定义时间轴数据 (`timelineData`) 和初始选中年份 (`activeYear`)。通过点击不同的年份,可以改变当前激活的年份,并有相应的视觉反馈。该组件支持均匀自适应排列,且易于在其他页面中引入和使用。
1482 0
Vue2时间轴(横向)
|
JavaScript 数据可视化
Vue引入Echarts词云图实现数据可视化(实现源码+案例)
本文主要讲Vue如何引入Echarts词云图实现数据可视化
2527 0
Vue引入Echarts词云图实现数据可视化(实现源码+案例)
|
运维 Linux 虚拟化
Linux 查看 CPU 使用情况
在 Linux 系统中,查看 CPU 使用情况是性能分析和故障排查的重要环节。查看 CPU 使用情况,使用 top 命令或者 htop 命令来查看。
|
JavaScript
Vue2日期选择器插件(vue-datepicker-local)
这是一个基于 Vue 的日期选择器组件库,支持年份、月份、日期和时间的选择,并且均可进行范围选择。用户可以自定义日期格式与组件样式。该示例展示了如何配置组件以限制可选日期范围,并提供了相应的代码实现。
2946 0
Vue2日期选择器插件(vue-datepicker-local)
Vue3时间轴(Timeline)
这是一个基于 Vue2 的时间轴(Timeline)组件,支持多种自定义属性,包括时间轴内容数组 `timelineData`、总宽度 `width`、线条样式 `lineStyle`、模式 `mode` 和位置 `position`。时间轴内容数组包含描述 `desc` 和圆圈颜色 `color`。组件提供了丰富的样式选项,如虚线、居中显示等,并支持内容交替展现。适用于多种场景下的时间轴展示需求。
1876 1
Vue3时间轴(Timeline)
|
缓存 JavaScript Java
vue2知识点:组件的props属性、非props属性、props属性校验
vue2知识点:组件的props属性、非props属性、props属性校验
582 4
|
资源调度 JavaScript Apache
Vue2使用echarts树图(tree)
这篇文章介绍了如何在Vue 3框架中集成echarts库来创建一个树状图(Tree Chart)组件,支持自定义数据和交互事件。
1280 0
Vue2使用echarts树图(tree)