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 鱼骨组件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 京东 Vue3 组件库支持小程序开发的详细流程

    京东 Vue3 组件库支持小程序开发的详细流程

    这篇文章主要介绍了京东 Vue3 组件库支持小程序开发的详细流程,通过引入NutUI,即可在项目中使用,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-06-06
  • Vue3(二)集成Ant Design Vue

    Vue3(二)集成Ant Design Vue

    上一篇文章我们介绍了利用Vue3 创建Vue CLI 项目(一),接下来就来看看Vue3集成Ant Design Vue 的相关资料,需要的小伙伴可以参考一下文章的具体内容
    2021-10-10
  • vue 中Virtual Dom被创建的方法

    vue 中Virtual Dom被创建的方法

    本文将通过解读render函数的源码,来分析vue中的vNode是如何创建的,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-04-04
  • 结合mint-ui移动端下拉加载实践方法总结

    结合mint-ui移动端下拉加载实践方法总结

    下面小编就为大家带来一篇结合mint-ui移动端下拉加载实践方法总结。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-11-11
  • Vue获取表单数据的多种方式

    Vue获取表单数据的多种方式

    这篇文章主要给大家介绍了关于Vue获取表单数据的多种方式,在Vue中我们通常使用v-model命令绑定表单的属性值(通常是value),获取到的属性值就是表单数据,需要的朋友可以参考下
    2023-09-09
  • vue常用指令实现学生录入系统的实战

    vue常用指令实现学生录入系统的实战

    本文主要介绍了vue常用指令实现学生录入系统的实战,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-02-02
  • 详解element-ui中form验证杂记

    详解element-ui中form验证杂记

    这篇文章主要介绍了详解element-ui中form验证杂记,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-03-03
  • vue 父组件通过v-model接收子组件的值的代码

    vue 父组件通过v-model接收子组件的值的代码

    这篇文章主要介绍了vue 父组件通过v-model接收子组件的值的代码,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-10-10
  • vue引用BootStrap以及引用bootStrap-vue.js问题

    vue引用BootStrap以及引用bootStrap-vue.js问题

    这篇文章主要介绍了vue引用BootStrap以及引用bootStrap-vue.js问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-10-10
  • 使用ElementUI修改el-tabs标签页组件样式

    使用ElementUI修改el-tabs标签页组件样式

    这篇文章主要介绍了使用ElementUI修改el-tabs标签页组件样式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-08-08

最新评论