forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeterministicProgress.vue
More file actions
78 lines (69 loc) · 1.69 KB
/
DeterministicProgress.vue
File metadata and controls
78 lines (69 loc) · 1.69 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template>
<div class="q-pa-md q-gutter-sm">
<q-btn
:loading="progress[0].loading"
:percentage="progress[0].percentage"
color="primary"
@click="startComputing(0)"
style="width: 150px"
>
Compute PI
<template v-slot:loading>
<q-spinner-gears class="on-left" />
Computing...
</template>
</q-btn>
<q-btn
:loading="progress[1].loading"
:percentage="progress[1].percentage"
round
color="secondary"
@click="startComputing(1)"
icon="cloud_upload"
/>
<q-btn
:loading="progress[2].loading"
:percentage="progress[2].percentage"
dark-percentage
unelevated
color="orange"
text-color="grey-9"
@click="startComputing(2)"
icon="cloud_upload"
style="width: 100px"
/>
</div>
</template>
<script>
import { ref, onBeforeUnmount } from 'vue'
export default {
setup () {
const progress = ref([
{ loading: false, percentage: 0 },
{ loading: false, percentage: 0 },
{ loading: false, percentage: 0 }
])
const intervals = [ null, null, null ]
function startComputing (id) {
progress.value[ id ].loading = true
progress.value[ id ].percentage = 0
intervals[ id ] = setInterval(() => {
progress.value[ id ].percentage += Math.floor(Math.random() * 8 + 10)
if (progress.value[ id ].percentage >= 100) {
clearInterval(intervals[ id ])
progress.value[ id ].loading = false
}
}, 700)
}
onBeforeUnmount(() => {
intervals.forEach(val => {
clearInterval(val)
})
})
return {
progress,
startComputing
}
}
}
</script>