分享

vue

 创始元灵6666 2022-08-05 发布于河北

效果图:

在这里插入图片描述

组件代码:

ProgressPlus.vue

<template>
  <div class="progress-plus" style="width: 100%">
    <div class="progress-box">
      <div class="gray" />
      <div class="colors" :style="setColor()" />
      <div class="icon icon1" />
      <div class="icon icon2" />
      <div class="icon icon3" />
      <div class="icon icon4" />
    </div>
    <span style="display: inline-block;padding-left: 5px" :style="{color:color}">{{ percent }}</span>
  </div>
</template>

<script>
export default {
  name: 'ProgressPlus',
  props: {
    color: {
      type: String,
      default: 'green'
    },
    percent: {
      type: Number,
      default: 0
    },
    width: {
      type: Number,
      default: 200
    }
  },
  methods: {
    setColor() {
      return {
        'background-color': this.color,
        'left': (this.percent - 100) + '%'
      }
    }
  }
}
</script>

<style scoped lang="scss">
.progress-plus{
  display: flex;
  &>span{
    width: 50px;
  }
  .progress-box{
    display: inline-block;
    position: relative;
    overflow: hidden;
    flex: 1;
    &>div{
      width: 100%;
      height: 10px;
    }
    .gray{
      background-color: gray;
    }
    .colors{
      /*background-color: green;*/
      position: absolute;
      top: 0;
      transition: left 1s;
    }

    .icon{
      position: absolute;
      width: 2px;
      bottom: 0;
      top: 0;
      background-color: #2d364b;
      &.icon1{
        left: 20%;
      }
      &.icon2{
        left: 40%;
      }
      &.icon3{
        left: 60%;
      }
      &.icon4{
        left: 80%;
      }
    }
  }
}
</style>

使用方法:

import ProgressPlus from './components/ProgressPlus'

components: { ProgressPlus }

<progress-plus style="width: 200px" :color="'#ff4941'" :percent="50" />

文章知识点与官方知识档案匹配,可进一步学习相关知识

显示推荐内容

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约