【发布时间】:2019-12-22 19:40:32
【问题描述】:
我正在使用 VueJS 和 Bootstrap-Vue 开发一个项目。我正在使用进度条作为加载屏幕的一部分。我希望它在 3 秒内顺利加载。我可以完成这项工作,但加载进度不稳定。
我使用 SetTimeOut 来推进进度条。我尝试了很多不同的时间组合,但我就是不能让它看起来足够平滑。
<template>
<div>
<div class="row pt-5">
<div class="col-md-12 text-center pt-5">
<h1>{{this.timer}}</h1>
<b-progress height="2rem" :striped=true show-progress :animated=true>
<b-progress-bar :value="value" variant="success">
<h5 v-if="value > 0">Loading</h5>
</b-progress-bar>
</b-progress>
<!--<b-progress height="2rem" variant="success" :value="value" show-progress class="mb-2"></b-progress>-->
</div>
</div>
</div>
</template>
<script>
import {mapActions, mapGetters} from 'vuex';
export default {
data() {
return {
timer: 4,
value: 0
}
},
mounted() {
this.startTimer();
},
methods: {
startTimer() {
let vm = this;
setTimeout(function () {
vm.timer = vm.timer - 0.1;
vm.value = vm.value + 7;
if (vm.timer !== 0) {
vm.startTimer();
} else {
console.log('done');
}
}, 25);
}
},
}
</script>
<style scoped>
</style>
有没有办法让进度条在指定的时间内平滑加载?
谢谢!
【问题讨论】:
标签: javascript laravel twitter-bootstrap vue.js