欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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
        // 這里剩余的值 必須按照比例去增加 才可以最終到達(dá)總值
        _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>

效果如下:

在這里插入圖片描述

遇到問題

在到達(dá)終點時,總數(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)文章

  • Vue2.x如何解決Element組件el-tooltip滾動時錯位不消失的問題

    Vue2.x如何解決Element組件el-tooltip滾動時錯位不消失的問題

    這篇文章主要介紹了Vue2.x如何解決Element組件el-tooltip滾動時錯位不消失的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Vue Element前端應(yīng)用開發(fā)之常規(guī)的JS處理函數(shù)

    Vue Element前端應(yīng)用開發(fā)之常規(guī)的JS處理函數(shù)

    在我們使用Vue Element處理界面的時候,往往碰到需要利用JS集合處理的各種方法,如Filter、Map、reduce等方法,也可以涉及到一些對象屬性賦值等常規(guī)的處理或者遞歸的處理方法,本篇隨筆列出一些在VUE+Element 前端開發(fā)中經(jīng)常碰到的JS處理場景,供參考學(xué)習(xí)。
    2021-05-05
  • Vue實例初始化為渲染函數(shù)設(shè)置檢查源碼剖析

    Vue實例初始化為渲染函數(shù)設(shè)置檢查源碼剖析

    這篇文章主要為大家介紹了Vue實例初始化為渲染函數(shù)設(shè)置檢查源碼剖析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Vue寶典之this.$refs屬性的使用

    Vue寶典之this.$refs屬性的使用

    Vue.js中的refs屬性是一個非常有用的特性,它允許我們在組件中操作 DOM 元素和組件實例,本文來介紹一下Vue寶典之this.$refs屬性的使用,感興趣的可以了解一下
    2023-12-12
  • vue移動端的左右滑動事件詳解

    vue移動端的左右滑動事件詳解

    這篇文章主要為大家詳細(xì)介紹了vue移動端的左右滑動事件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • vue實現(xiàn)下拉框的多選功能(附后端處理參數(shù))

    vue實現(xiàn)下拉框的多選功能(附后端處理參數(shù))

    本文介紹了如何使用Vue實現(xiàn)下拉框的多選功能,實現(xiàn)了在選擇框中選擇多個選項的功能,文章詳細(xì)介紹了實現(xiàn)步驟和示例代碼,對于想要了解如何使用Vue實現(xiàn)下拉框多選功能的讀者具有一定的參考價值
    2023-08-08
  • vue 中固定導(dǎo)航欄的實例代碼

    vue 中固定導(dǎo)航欄的實例代碼

    今天小編就為大家分享一篇vue 中固定導(dǎo)航欄的實例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • Vue導(dǎo)入excel文件的兩種方式(form表單和el-upload)

    Vue導(dǎo)入excel文件的兩種方式(form表單和el-upload)

    最近開發(fā)遇到一個點擊導(dǎo)入按鈕讓excel文件數(shù)據(jù)導(dǎo)入的需求,下面這篇文章主要給大家介紹了關(guān)于Vue導(dǎo)入excel文件的兩種方式,分別是form表單和el-upload兩種方法,需要的朋友可以參考下
    2022-11-11
  • Tree-Shaking?機制快速掌握

    Tree-Shaking?機制快速掌握

    這篇文章主要為大家介紹了Tree-Shaking?機制的快速掌握教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02
  • vue3+vite中使用import.meta.glob的操作代碼

    vue3+vite中使用import.meta.glob的操作代碼

    在vue2的時候,我們一般引入多個js或者其他文件,一般使用? require.context 來引入多個不同的文件,但是vite中是不支持 require的,他推出了一個功能用import.meta.glob來引入多個,單個的文件,下面通過本文介紹vue3+vite中使用import.meta.glob,需要的朋友可以參考下
    2022-11-11

最新評論