-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_vue.html
145 lines (113 loc) · 3.39 KB
/
test_vue.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<body>
<div id="app">
<ul>
<li v-for="item in result">
#{ item.title }
</li>
</ul>
<button @click="start">Lancer le décompte</button>
<div id="bip" class="display"> #{ duree } </div>
</div>
<script>
// var counter = 10;
// var intervalId = null;
// function finish() {
// counter = 10;
// clearInterval(intervalId);
// document.getElementById("bip").innerHTML = "TERMINE!";
// }
// function bip() {
// counter--;
// if(counter == 0) finish();
// else {
// document.getElementById("bip").innerHTML = counter + " secondes restantes";
// }
// }
// function start(){
// intervalId = setInterval(bip, 1000);
// }
</script>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!-- Moment.js library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<!-- moment-duration-format plugin -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-duration-format/1.3.0/moment-duration-format.min.js"></script>
<script type="text/javascript">
const app = new Vue({
el: "#app",
data: {
message: 'Hello Vue!',
result : [],
base_usl : "https://jsonplaceholder.typicode.com/todos",
counter : 3600,
intervalId : null,
duree: "10",
},
delimiters: ["#{", "}"],
mounted: function() {
this.get()
},
methods: {
finish: function(){
this.counter = 3600;
clearInterval(this.intervalId);
this.duree = "Terminer"
},
bip: function(){
this.counter--;
if(this.counter == 0){
this.finish();
}
else {
var duration = moment.duration(this.counter, 'seconds');
var formatted = duration.format("hh:mm:ss");
this.duree = formatted ;
}
},
start: function(){
console.log("start")
this.intervalId = setInterval(this.bip, 1000);
},
get: function(){
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = 'X-CSRFToken'
axios.get(this.base_usl)
.then(response => {
resultat = response.data
//this.result = resultat
console.log('getting..')
//console.log(resultat)
//this.contentA = myshop[0].fields.code_depart
//console.log(response.data)
//this.loading = false;
})
.catch((err) => {
//this.loading = false;
console.log(err);
})
}
}
});
// $(document).ready(function() {
// setInterval( function(){
// app.get()
// }, 1000);
// });
// var seconds = 3820;
// var duration = moment.duration(seconds, 'seconds');
// var formatted = duration.format("hh:mm:ss");
// console.log(formatted);
</script>
</body>
</html>