vue 自定义组件:ProcessBar (堆叠式进度条)

在这里插入图片描述
使用vue做界面的时候需要用到类似bootstrap堆叠式进度条,前台使用ElementUI,为了防止有样式冲突,自己定义一个类似这样的进度条。

<template>
  <div id="ProcessBar" class="pB_Container">
    <div class="first" :style="error">
      {{ getProcessDesc(processValue[0]) }}
    </div>
    <div class="second" :style="cancel">
        {{ getProcessDesc(processValue[1]) }}
    </div>
    <div class="third" :style="success">
       {{ getProcessDesc(processValue[2]) }}
    </div>
    <div class="last" :style="notDone">
      {{ getProcessDesc(processValue[3]) }}
    </div>
  </div>
</template>

<script>
export default {
  name: "ProcessBar",
  props: {
    processValue: {
      type: Array,
      default: [0],
    },
  },
  data() {
    return {
      error: {
        width: this.processValue[0] + "%",
      },
      cancel: {
        width: this.processValue[1] + "%",
      },
      success: {
        width: this.processValue[2] + "%",
      },
      notDone: {
        width: this.processValue[3] + "%",
      },
    };
  },
  components: {},
  methods: {
    getProcessDesc(data) {
      return data == 0 ? " " : data + "%";
    },
  },
};
</script>
<style scoped>
.pB_Container {
  width: 100%;
  background-color: #f5f5f5;
  height: 20px;
  display: inline-flex;
  line-height: 20px;
  text-align: right;
  overflow: hidden;
  color: white;
  box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.1);
}
.pB_Container div {
  float: left;
  border-radius: 8px;
}
.first {
  background-color: #ea6b66;
  padding-right:10px
}
.second {
  background-color: #ffd966;
   padding-right:10px
}
.third {
  background-color: #7ea6e0;
   padding-right:10px
}
.last {
  background-color: white;
   padding-right:10px
}
</style>

在父级中引入组件 直接调用:

<template>
  <div class="pB_Container">
    <processBar v-bind="processBarModel" />
  </div>
</template>

<script>
import processBar from "../components/processPar";
export default {
  name: "Home",
   components: {
    processBar,
  },
  data() {
    return {
      processBarModel: {
        processValue: [10, 40, 20, 0]//此处是每个进度的值
      },
    };
  },
 
};
</script>

在这里插入图片描述

案例只设置了4级进度 , 没有根据值的个数来循环加载进度个数,待优化。。。。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

急景流年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值