progress.vue
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<progress
:class="[progressVariant, striped ? 'progress-striped' : '', animated ? 'progress-animated' : '']"
:value="value"
:max="max"
:aria-valuenow="value"
:aria-valuemin="0"
:aria-valuemax="max"
ref="progress">
<div class="progress">
<span class="progress-bar" :style="{width: value + '%'}" ref="progressbar"></span>
</div>
</progress>
</template>
<script>
export default {
replace: true,
computed: {
progressVariant() {
return !this.variant || this.variant === `default` ? `progress` : `progress progress-${this.variant}`;
}
},
props: {
striped: {
type: Boolean,
default: false
},
animated: {
type: Boolean,
default: false
},
value: {
type: Number,
default: 0
},
max: {
type: Number,
default: 100
},
variant: {
type: String,
default: 'default'
}
},
mounted() {
this._progress = this.$refs.progress;
this._progressBar = this.$refs.progressbar;
this._progressBar.style.width = this.value + '%';
this._progress.setAttribute('value', this.value);
},
watch: {
value(val) {
this._progress.setAttribute('value', val);
this._progressBar.style.width = this.value + '%';
}
}
};
</script>