小程序&vue 加载进度功能

<div class="circle" v-if="circleOpen">
      <van-overlay :show="overlayOpen" />
      <div class="number">
        <van-circle
          v-model="percentage"
          :rate="5"
          :speed="100"
          :stroke-width="80"
          :color="gradientColor"
          :text="percentage + '%'"
        />
        <!-- <div class="dot">动态省略号<span class="dot-ani"></span></div> -->
        <span>{{percentage<20&&percentage>12?'正在合成背景':percentage<40?'正在合成视频':percentage<60?'正在适配数字人动作':percentage<80?'正在适配数字人语音':percentage<100?'正在渲染整体效果':''}}<span class="dot-ani"></span> </span>
      </div>
    </div>
// 组件数据
data() {
 return {
  	percentage: 10, //进度条数字
    loadingTimer: "", //进度条定时器
    loadingTimerTwo: "", //进度条定时器2
 }
} 
/* 
 提交制作合成进度条loading 
*/
    scheduleLoading() {
      let that = this
      this.circleOpen = true //进度条
      let percentage = that.percentage
      that.loadingTimer = setInterval(function () {
        percentage++
        console.log("datas", percentage>=60)
        that.percentage=percentage
        if (that.percentage >= 80) {
          clearInterval(that.loadingTimer)
          //进度条由快到慢,80%后800毫秒跑一次到97%清除定时器
          that.loadingTimerTwo = setInterval(function () {
            percentage++
            that.percentage= percentage
            if (that.percentage >= 97) {
              clearInterval(that.loadingTimerTwo)
            }
          }, 800)
        }
      }, 400)
    },

//销毁页面时退出定时器
destroyed(){
  clearInterval(this.loadingTimer)
  clearInterval(this.loadingTimerTwo)
}


//不断跳动的省略号
.dot-ani {
      display: inline-block;
      height: 12px;
      line-height: 12px;
      overflow: hidden;
    }
    .dot-ani::after {
      display: inline-table;
      white-space: pre;
      content: "\A.\A..\A...\A....\A.....\A......";
      animation: spin 2s steps(4) infinite;
    }
    @keyframes spin {
      to{
        -webkit-transform:translateY(-48px);
        transform:translateY(-48px)
      }
    }

小程序

<view class="overlay">
    <van-overlay show="{{ showloadding }}">
      <view class="wrapper" style="z-index: 1000;">
        <van-circle value="{{ percentage }}" color="#0063a8">
          <text style="color: #0063a8;">{{percentage}}%</text>
        </van-circle>
        <text class="wrapperText">视频正在热火朝天地制作中</text>
      </view>
    </van-overlay>
  </view>

	loadingTimer: "", //全局定时器
    loadingTimerTwo: "", //全局定时器2
    percentage: 10, //进度条数字

/* 
   提交制作合成进度条loading 
  */
  loading() {
    let self = this
    let percentage = self.data.percentage
    self.data.loadingTimer = setInterval(function () {
      percentage++
      console.log("datas", percentage)
      self.setData({
        percentage: percentage
      })
      if (self.data.percentage >= 93) {
        console.log('我开始计时达到93%')
        clearInterval(self.data.loadingTimer)
        //进度条由快到慢,93%后一秒跑一次到99%清除定时器
        self.data.loadingTimerTwo = setInterval(function () {
          percentage++
          self.setData({
            percentage: percentage
          })
          if (self.data.percentage >= 99) {
            clearInterval(self.data.loadingTimerTwo)
          }
        }, 1000)
      }
    }, 200)
  },

引入组件

{
  "usingComponents": {
    "van-circle": "/miniprogram_npm/@vant/weapp/circle/index",
    "van-overlay": "/miniprogram_npm/@vant/weapp/overlay/index"
  }
}```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,我可以帮你写一个Vue项目实现页面进度条。 首先,在Vue项目中可以使用NProgress库来实现页面进度条的功能。你可以通过npm安装NProgress库,然后在main.js文件中引入它。 ```javascript import NProgress from 'nprogress' import 'nprogress/nprogress.css' NProgress.configure({ showSpinner: false }) ``` 然后,在路由导航守卫中使用NProgress来控制进度条的显示和隐藏。在beforeEach函数中,使用NProgress.start()来显示进度条;在afterEach函数中使用NProgress.done()来隐藏进度条。 ```javascript router.beforeEach((to, from, next) => { NProgress.start() next() }) router.afterEach(() => { NProgress.done() }) ``` 最后,在模板中添进度条的HTML代码。可以放在App.vue文件的template标签中。 ```html <template> <div> <div class="bar" role="bar"></div> </div> </template> <style> .bar { position: fixed; z-index: 1031; top: 0; left: 0; width: 100%; height: 2px; background-color: #46c477; -webkit-transition: height .3s 0s; transition: height .3s 0s; } .nprogress-fade-enter { opacity: 0; } .nprogress-fade-enter-active { opacity: 1; } .nprogress-fade-exit { opacity: 1; } .nprogress-fade-exit-active { opacity: 0; } </style> ``` 这个HTML代码中,我们添了一个class名为“bar”的div标签用来显示进度条。另外,为了美化进度条,我们还添了一些CSS样式。 综上所述,以上就是基于NProgress库的Vue项目页面进度条的实现方法,你可以参考一下。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

湾流~

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

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

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

打赏作者

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

抵扣说明:

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

余额充值