手写实现timeline时间线组件

先看效果图

手写实现timeline时间线组件_第1张图片

template部分
  <div class="g-steps">
    <div class="steps-list" v-if="steps.length">
      <div class="step-item flex align-items-center" v-for="(item, index) in steps">
        <span>{{ index + 1 }}</span>
        <div class="content">
          <p class="title">{{ item.title }}</p>
          <p class="time">{{ item.lastModifiedAt }}</p>
        </div>
      </div>
    </div>
  </div>
js部分
<script setup lang="ts">
import { formatDate } from '@/utils/common';

type Props = {
  steps: {
    title: string,
    lastModifiedAt: string
  }[]
}
const props = defineProps<Props>()
</script>
style部分
<style scoped lang="scss">
.g-steps {
  .steps-list {

    .step-item {
      position: relative;

      &::before {
        content: '';
        position: absolute;
        height: 100%;
        top: 50%;
        left: 10px;
        width: 1px;
        background-color: rgba(0, 0, 0, 0.12);
        z-index: -1;
      }

      &:last-child {
        &::before {
          content: none;
        }
      }

      span {
        display: inline-block;
        background-color: #9e9d9e;
        width: 22px;
        height: 22px;
        border-radius: 50%;
        text-align: center;
        color: white;
        line-height: 22px;
      }

      .content {
        margin-left: 12px;
        margin-top: 8px;
        padding: 8px;
        width: 100%;
        background-color: #F9F9F9;

        p {
          line-height: 24px;
        }

        p.time {
          color: #B8B8B8;
          font-size: 12px;
        }
      }
    }
  }

  .p-steps {
    :deep(.p-steps-list) {
      flex-direction: column;

      li {
        &::before {
          background-color: rgba(0, 0, 0, 0.12);
          height: 100%;
          left: 18px;
          top: 18px;
          width: 1px;
        }
      }

      .p-steps-item {
        &::before {
          position: absolute;
        }
      }
    }

  }
}
</style>

你可能感兴趣的:(前端开发,css3,html)