-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathApp.js
92 lines (77 loc) · 2.04 KB
/
App.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import LoadingBar from './components/';
import '../css/loading-bar.css';
export default {
data() {
return {
progress: 0,
error: false,
direction: 'right'
}
},
render(h) {
let {
progress, error, direction,
progressTo, changeDirection, setToError, errorDone, progressDone } = this
return (
<div>
<LoadingBar
onErrorDone={ errorDone }
onProgressDone={ progressDone }
progress={ progress }
direction={ direction }
error={ error } />
<div class="main">
<h1 align="center">Vue Loading Bar</h1>
<p align="center">Progress is { progress }%</p>
<div class="button-container">
<button type="button" on-click={ progressTo.bind(this,30) }>Progress to 30</button>
<button type="button" on-click={ progressTo.bind(this,50) }>Progress to 50</button>
<button type="button" on-click={ progressTo.bind(this,100) }>Progress to 100</button>
<button type="button" on-click={ changeDirection }>Change Direction</button>
<button class="error" type="button" on-click={ setToError.bind(this,true) }>Give An Error</button>
</div>
</div>
</div>
)
},
methods: {
// Events
progressTo(number) {
this.progress = number
},
changeDirection() {
if(this.progress >= 0){
this.progress = 100
}
this.direction = this.direction === 'right' ? 'left' : 'right'
},
setToError(bool){
this.error = bool
},
// Callback
errorDone(){
this.error = false
},
progressDone() {
this.progress = 0
},
},
mounted () {
var self = this
self.progress = 10;
for (var i = 0; i < 30; i++) {
if(i > 20 && i < 29){
setTimeout(function () {
self.progress += 5;
},50*i);
}else{
setTimeout(function () {
self.progress ++;
},10*i);
}
}
setTimeout(function () {
self.progress = 100;
},1500);
}
};