vue3+ts+elementplus 进度条制作浏览器进度条

开发工具:vue3 + ts + elementplus + el-progress

NProgress

在布署的时候,Jenkins总是提示失败,指向NProgress的问题,但是我却不知道为何,找不到相关解决方案,一气之下,就打算用别的方案了。

javascript 复制代码
<template>
  <div class="wrapper-progress">
    <Transition name="fade">
      <el-progress v-if="show" v-bind="attrs" :color="colors" :percentage="perc" :show-text="false" stroke-width="3" />
    </Transition>
  </div>
</template>
<script setup lang="ts">
import { ref, defineProps, defineEmits, computed, useAttrs } from "vue";
import type { Ref } from "vue";
const attrs = useAttrs(); //所有非defineProps中定义的属性

const emits = defineEmits(["start", "finish", "update:size"]);

// 组件属性
const props = defineProps({
  percentage: {
    type: Number,
    default: 20,
  },
  setp: {
    type: Number,
    default: 8,
  },
  per: {
    type: Number,
    default: 150,
  },
});
let maxNum: number = 90;
const colors: Object[] = [
  { color: "#f56c6c", percentage: 20 },
  { color: "#e6a23c", percentage: 40 },
  { color: "#5cb87a", percentage: 60 },
  { color: "#1989fa", percentage: 80 },
  { color: "#36CEBF", percentage: 100 },
];

let show: Ref<boolean> = ref(false);
let perc: any = ref(0);

//开始事件
const start = () => {
  show.value = true;
  function task() {
    if (perc.value > maxNum) {
      perc.value = maxNum;
      clearInterval(intervalID);
    }
    perc.value = perc.value + props.setp;
  }

  // 执行
  let intervalID = setInterval(() => {
    task();
  }, props.per);
};

// 完成事件
const finish = () => {
  perc.value = 100;
  setTimeout(() => {
    show.value = false;
  }, 500);
};

defineExpose({
  start,
  finish,
});
</script>

<style lang="scss" scoped>
.wrapper-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 10px;
  z-index: 999;

  .fade-enter-active,
  .fade-leave-active {
    transition: opacity 0.5s ease;
  }

  .fade-enter-from,
  .fade-leave-to {
    opacity: 0;
  }
}
</style>
相关推荐
做前端的娜娜子10 分钟前
同一链接实现 PC Web 与移动 H5 自适应
前端·掘金·金石计划
小帅不太帅17 分钟前
架构没变、规模没变,DeepSeek V4 Flash 正式版凭什么暴涨 47 分?
前端·aigc·deepseek
jarvisuni42 分钟前
DeepSeekFlash前端依旧拉垮,而且变慢了很多!
前端·javascript·算法
卷福同学2 小时前
AI编程出海第二步:验证关键词能否做站
前端·人工智能·后端
赵庆明老师2 小时前
Vben精讲:21-详解web-antd:tsconfig.json
前端·json·vim
wc882 小时前
微软EDGE浏览器功能学习
前端·学习·edge
破z晓2 小时前
javascript 导出excel表
开发语言·javascript·excel
Csvn3 小时前
🎯 原生 `<dialog>` 元素:终于可以扔掉一半的自定义弹窗组件了?
前端
Csvn3 小时前
🎨 CSS @layer:用「层叠优先级」终结样式打架的世纪难题
前端
小罗水4 小时前
第17章 后台管理端与演示支持
javascript·vue.js·ecmascript