Vue 使用html、css实现鱼骨组件图

 更新时间:2024年07月05日 14:46:01   作者:Lucky_Turtle  
这篇文章主要介绍了Vue 使用html、css实现鱼骨组件图,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧

预览图

在这里插入图片描述

组件

<template>
  <div class="context">
    <div class="top">
      <div class="label-context">
        <div class="label" v-for="(item, index) in value" :key="index">
          <div class="label-text" v-if="index % 2 === 0">
            {{ item.label }}
          </div>
          <div class="connect-line-box" v-if="index % 2 === 0">
            <div class="connect-line"><i class="center-line-icon"></i></div>
          </div>
        </div>
      </div>
    </div>
    <div class="center-line">
      <div class="icon-box" v-for="(item, index) in value" :key="index">
        <i class="center-line-icon"></i>
      </div>
    </div>
    <div class="bottom">
      <div class="label-context">
        <div class="label" v-for="(item, index) in value" :key="index">
          <div class="connect-line-box" v-if="index % 2 === 1">
            <div class="connect-line"></div>
          </div>
          <div class="label-text" v-if="index % 2 === 1">
            {{ item.label }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'FishBoneComponent',
  props: {
    value: {
      type: Array,
      default: () => [
        {
          time: '2024-06-13 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
        {
          time: '2024-06-12 15:27:30',
          label: ''
        },
      ]
    }
  },
  mounted() {
    this.value = this.value.sort((a, b) => {
      return new Date(a.time) - new Date(b.time);
    });
    console.log(this.value)
  }
}
</script>
<style lang="scss" scoped>
$center-color: #1890ff;
$text-box-width: 200px;
$text-margin-left: 10px;
$line-height: 40px;
$add-width: 0px;
$line-icon-size: 13px;
.context {
  width: 100%;
  padding: 0.5%;
  height: 100%;
}
.center-line {
  position: absolute;
  height: 2px;
  background-color: $center-color;
  width: 98%;
  display: flex;
  align-items: center;
  justify-content: left;
}
.center-line::after {
  content: '';
  position: absolute;
  top: 50%;
  right: -10px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 10px solid $center-color;
  transform: translateY(-50%);
}
.center-line .icon-box:first-child {
  margin-left: $text-margin-left;
  width: $text-box-width/2 + $line-icon-size/2;
  flex-shrink: 0;
  i {
    float: right;
    width: $line-icon-size;
    height: $line-icon-size;
    flex-shrink: 0;
  }
}
.center-line .icon-box:not(:first-child) {
  margin-left: $text-margin-left - $line-icon-size/2;
  width: $text-box-width/2 + $line-icon-size/2;
  flex-shrink: 0;
  i {
    float: right;
    width: $line-icon-size;
    height: $line-icon-size;
    flex-shrink: 0;
  }
}
.center-line-icon {
  width: $line-icon-size;
  height: $line-icon-size;
  background-color: $center-color;
  border-radius: 50%;
}
.top .label-context {
  display: flex;
  flex-direction: row;
  justify-content: normal;
}
.connect-line-box {
  display: flex;
  flex-direction: row;
  text-align: center;
  justify-content: center;
}
.connect-line {
  width: 2px;
  height: $line-height;
  background-color: #1d71fa;
}
.top .label {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  margin-left: $text-margin-left;
}
.label > div {
  width: $text-box-width;
  margin-left: $add-width;
  white-space: normal;
}
.bottom .label-context {
  display: flex;
  flex-direction: row;
  justify-content: normal;
  margin-left: $text-box-width/2;
}
.bottom .label {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  margin-left: $text-margin-left;
}
.label-text {
  padding: 6px;
  background-color: rgb($center-color, 0.08);
  border-radius: 3px;
  color: black;
  font-size: 15px;
}
</style>

测试案例

<template>
  <div class="card">
    <FishBoneComponent :value="data"></FishBoneComponent>
  </div>
</template>
<script>
import FishBoneComponent from "@/views/FishBoneComponent";
export default {
  name: "FishBone",
  components: {FishBoneComponent},
  data(){
    return{
      data: [
        {
          time: '2024-06-13 15:27:30',
          label: '测试测试测试测试测试测试测试测试测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试测试测试测试测试测试测试测试测试测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试测试测试测试测试测试测试测试测试测试测试测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试测试测试测试测试测试测试测试测试测试测试测试测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试'
        },
        {
          time: '2024-06-12 15:27:30',
          label: '测试'
        },
      ]
    }
  }
}
</script>
<style scoped>
.card{
  padding: 8px;
}
.title-box{
  margin-bottom: 8px;
}
.title{
  font-size: 18px;
  font-weight: bold;
  color: #1890ff;
}
</style>
</style>

到此这篇关于Vue 使用html、css实现鱼骨组件的文章就介绍到这了,更多相关Vue 鱼骨组件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • vue项目中销毁window.addEventListener事件监听解析

    vue项目中销毁window.addEventListener事件监听解析

    这篇文章主要介绍了vue项目中销毁window.addEventListener事件监听,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-07-07
  • Vue3中如何修改父组件传递到子组件中的值(全网少有!)

    Vue3中如何修改父组件传递到子组件中的值(全网少有!)

    大家都知道,vue是具有单向数据流的传递特性,下面这篇文章主要给大家介绍了关于Vue3中如何修改父组件传递到子组件中值的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2023-04-04
  • 在vue中实现禁止回退上一步,路由不存历史记录

    在vue中实现禁止回退上一步,路由不存历史记录

    这篇文章主要介绍了在vue中实现禁止回退上一步,路由不存历史记录,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-07-07
  • vue.js实现刷新当前页面的方法教程

    vue.js实现刷新当前页面的方法教程

    这篇文章主要给大家介绍了关于vue.js实现刷新当前页面的方法教程,文中给出了详细的示例代码供大家参考学习,对大家具有一定的参考学习价值,需要的朋友们下面跟着小编一起来学习学习吧。
    2017-07-07
  • 在React和Vue中使用Mock.js模拟接口的实现方法

    在React和Vue中使用Mock.js模拟接口的实现方法

    本文将介绍如何在React和Vue项目中使用Mock.js来模拟接口拦截请求,帮助开发者在不依赖后端的情况下高效地进行前端开发,文中有详细的代码示例供大家参考,需要的朋友可以参考下
    2024-08-08
  • 详解Vue微信授权登录前后端分离较为优雅的解决方案

    详解Vue微信授权登录前后端分离较为优雅的解决方案

    这篇文章主要介绍了详解Vue微信授权登录前后端分离较为优雅的解决方案,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-06-06
  • vue中Promise的使用方法详情

    vue中Promise的使用方法详情

    这篇文章主要介绍了vue中Promise的使用方法详情,Promise可以说是异步编程的一种解决方法,主要是为了解决代码乱的情景而出现的,下文介绍其具体用法,需要的小伙伴可以参考一下
    2022-03-03
  • Vue首屏加载过慢出现长时间白屏的实现

    Vue首屏加载过慢出现长时间白屏的实现

    本文主要介绍了Vue首屏加载过慢出现长时间白屏的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-04-04
  • vue3.0如何使用computed来获取vuex里数据

    vue3.0如何使用computed来获取vuex里数据

    这篇文章主要介绍了vue3.0如何使用computed来获取vuex里数据问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-04-04
  • 如何使用Vue3.2+Vite2.7从0快速打造一个UI组件库

    如何使用Vue3.2+Vite2.7从0快速打造一个UI组件库

    构建工具使用vue3推荐的vite,下面这篇文章主要给大家介绍了关于如何使用Vue3.2+Vite2.7从0快速打造一个UI组件库的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-09-09

最新评论