使用 element-ui 的 el-progress 寫的進度條

<template>
    <div class="scaleProgress">
        <el-progress :text-inside="true" :stroke-width="18" :percentage="progressNum"></el-progress>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                progressNum: 10,
                startTimer: '',
                endTimer: ''
            }
        },
        props: {
            progressStatus: {
                type: Boolean,
                default() {
                    return false
                }
            }
        },
        watch: {
            progressStatus (val) {
                if (val) {
                    this.endProgress()
                }
            }
        },
        methods: {
            startProgress () {
                this.startTimer = setInterval(() => {
                    this.progressNum ++
                    if (this.progressNum > 85) {
                        clearInterval(this.startTimer)
                    }
                }, 100); 
            },
            endProgress () {
                clearInterval(this.startTimer)
                this.endTimer = setInterval(() => {
                    this.progressNum ++
                    if (this.progressNum > 99) {
                        clearInterval(this.endTimer)
                        this.finishProgress()
                    }
                }, 10);
            },
            finishProgress () {
                this.$emit('finishProgress', false)
            }
        },
        mounted() {
            this.startProgress()
        }
    }
    // 使用示例
    // import sProgress from 'components/common/SProgress'
    // <s-progress @finishProgress="closeProgress" v-if="showProgress" :progressStatus="progressStatus"></s-progress>                     
    // closeProgress (val) {
    //     this.showProgress = val
    //     this.progressStatus = val
    // },
    // save () {
    //     this.showProgress = true
    //     setTimeout(() => {
    //         this.progressStatus = true
    //     }, 3000)
    // },
</script>
<style scoped>
.scaleProgress {
    transform: scaleY(0.75);
}
</style>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章