<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./vue-2.4.0.js"></script>
</head>
<body>
<div id="app">
<h2 v-html>{{msg.toFixed(2)}}</h2>
<button @click="change1" :disabled="flag">开始计时</button>
<button @click="stop1" :disabled="!flag">暂停计时</button>
</div>
</body>
<script>
var va = new Vue({
el: '#app',
data: {
msg:0,
flag:null,
timer:null,
n:0,
m:0
},
methods: {
change1(){
this.flag=!this.flag
this.timer = setInterval(()=>{
this.n++
if(this.n == 100){
this.n = 0,
this.m++
}
this.msg = Number(this.m)+Number((this.n/100))
},10)
},
stop1(){
clearInterval(this.timer)
if(this.msg == 10){
alert('成功了')
}else{
alert('失败了')
}
this.flag=!this.flag
}
}
})
</script>
</html>
vue 实现十秒计时器
最新推荐文章于 2024-06-19 09:49:44 发布