最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue項目之?dāng)?shù)量占比進度條實現(xiàn)方式

 更新時間:2022年12月06日 14:45:21   作者:牛先森家的牛奶  
這篇文章主要介紹了vue項目之?dāng)?shù)量占比進度條實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

vue數(shù)量占比進度條實現(xiàn)

功能說明:

1、點擊開始,滾動條自動加;

2、點擊停止,滾動條停止加;

封裝如下

<template>
  <div>
    <div class="progress-bar">
      <div
        class="progress"
        :style="{
          width: progressRatio + '%'
        }"
      >
        {{ surplusProgress }}
      </div>
      {{ totalProgress }}
    </div>
    {{ surplusProgress }}
    <button @click="start()">開始</button>
    <button @click="stop()">停止</button>
  </div>
</template>

<script>
export default {
  name: 'index',
  components: {},
  props: {
    total: {
      type: Number
    },
    surplus: {
      type: Number
    }
  },
  data() {
    return {
      totalProgress: 0,
      surplusProgress: 0,
      progressRatio: 0,
      clearInt: null // 定時器名
    }
  },
  computed: {
    // 用于監(jiān)聽兩個值同時存在的情況
    progress() {
      const { surplus, total } = this
      return {
        surplus,
        total
      }
    }
  },
  watch: {
    progress(newVal) {
      this.totalProgress = newVal.total
      this.surplusProgress = newVal.surplus
      // 注意這里是當(dāng)前剩余的值比上總值的一個比例顯示
      this.progressRatio = (newVal.surplus / newVal.total) * 100
    }
  },
  methods: {
    start() {
      let _this = this
      // 增加的值 = 總數(shù)量 / 100
      let addNum = _this.totalProgress / 100
      clearInterval(_this.clearInt)
      _this.clearInt = setInterval(function () {
        _this.progressRatio = _this.progressRatio + 1
        // 這里剩余的值 必須按照比例去增加 才可以最終到達總值
        _this.surplusProgress = ((_this.surplusProgress * 100 + addNum * 100) / 100).toFixed(1)
        if (_this.progressRatio >= 100) {
          clearInterval(_this.clearInt)
          _this.progressRatio = _this.progressRatio
          _this.surplusProgress = parseInt(_this.surplusProgress)
        }
      }, 100)
    },
    stop() {
      clearInterval(this.clearInt)
    }
  }
}
</script>

<style  lang="scss" scoped>
.progress-bar {
  width: 500px;
  height: 30px;
  color: #000;
  text-align: center;
  line-height: 30px;
  box-sizing: border-box;
  margin-top: 50px;
  margin-bottom: 20px;
  border: 1px solid gray;
  box-shadow: -1px -1px 1px #000;
  background: rgb(177, 174, 174);
  position: relative;
  .progress {
    height: 100%;
    background: #3165c5;
    color: #fff;
    overflow: hidden;
    position: absolute;
    opacity: 0.5;
    text-align: center;
  }
}
</style>

組件使用

<template>
  <div class="content-box">
    <div class="container">
      <Progress :total="total1" :surplus="surplus1" />
      <Progress :total="total2" :surplus="surplus2" />
    </div>
  </div>
</template>

<script>
import Progress from '@/components/ProgressBar'
export default {
  name: 'record',
  components: {
    Progress
  },
  data() {
    return {
      surplus1: 0,
      total1: 0,
      surplus2: 0,
      total2: 0
    }
  },
  activated() {
    let _this = this
    // 模擬請求情況
    setTimeout(() => {
      _this.surplus1 = 30
      _this.total1 = 100
      _this.surplus2 = 60
      _this.total2 = 220
    }, 3000)
  },
  methods: {},
  mounted() {}
}
</script>

<style scoped>
</style>

效果如下:

在這里插入圖片描述

遇到問題

在到達終點時,總數(shù)和剩余值不一致問題,查明問題原因是小數(shù)點的問題,目前保留一位小數(shù)點;

vue實現(xiàn)進度條效果

這里實現(xiàn)進度條用到了es6語法的模版字符串,通過更改css樣式實現(xiàn)正常顯示進度的進度條和一種顯示剩余余額的進度條:

html代碼不需要改變:

<div class="scheduleCont_1_left_1" :class="10 >= 100 ? 'nobg' : ''">
		//10為展示的進度,100為總的進度數(shù)量
     <div :style="{ width: `${(10 / 100).toFixed(2) * 100}%` }" class="un_xg_1_3_1"></div>
</div>

正常顯示進度的進度條:

.scheduleCont_1_left_1{
    position: relative;
    width: 100%;
    height: 0.36rem;
    background: #E9BBFF;
    border-radius: 50px;
    overflow: hidden;
    .un_xg_1_3_1 {
      position: absolute;
      top: 0;
      left: -1px;
      width: 0;
      height: 0.36rem;
      border-radius: 50px;
      background-image: linear-gradient(to right, #B72DF7);
    }
  }

顯示剩余余額的進度條:

.scheduleCont_1_left_1 {
  position: relative;
  width: 100%;
  height: .24rem;
  background: #ebebeb;
  border-radius: 50px;
  overflow: hidden;

  .un_xg_1_3_1 {
    float: right;
    height: .24rem;
    border-radius: 50px;
    background-image: linear-gradient(to right, #ff6666);
  }
}

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

济南市| 得荣县| 巴塘县| 永兴县| 天峻县| 金秀| 荣成市| 万山特区| 大关县| 靖西县| 温宿县| 井研县| 永福县| 宾阳县| 嘉兴市| 项城市| 垣曲县| 耿马| 马关县| 无为县| 福建省| 邵武市| 上饶市| 孟村| 名山县| 永安市| 澄城县| 罗平县| 延吉市| 绍兴市| 辰溪县| 台北县| 五华县| 鄄城县| 崇明县| 竹北市| 双鸭山市| 津市市| 景洪市| 定结县| 社旗县|