随机模板
<template>
<div>
<div class="box">
<span >
  
</span>
<div class="qs">{{ word }}</div>
</div>
<div class="btns">
<van-button plain type="primary" class="start" @click="btnFnStart">开始抽奖</van-button>
<van-button plain type="primary" class="end" @click="btnFnEnd">暂停</van-button>
</div>
</div>
</template>
<script>
export default{
data() {
return{
word:"奖项",
name:["一等奖","二等奖","三等奖","谢谢惠顾","再来一次奖","掌声鼓励一下奖","木有奖","没有奖"],
timer:"",
jianname:"",
};
},
methods:{
btnFnStart(){
clearInterval(this.timer);
this.timer = setInterval(this.fn,100);
},
fn(){
let num = Math.floor(Math.random()*this.name.length);
this.word = this.name[num];
this.jianname = this.name[num];
},
btnFnEnd(){
clearInterval(this.timer);
this.name.forEach((item,index)=>{
if(item==this.jianname){
this.name.splice(index,1);
}
if(this.name.length==0){
this.word = "网络异常";
}
})
}
},
mounted() {
}
}
</script>
<style>
* {
margin: 0;
padding: 0;
}
h2 {
text-align: center;
}
.box {
width: 600px;
margin: 50px auto;
display: flex;
font-size: 25px;
line-height: 40px;
}
.qs {
width: 450px;
height: 40px;
color: red;
text-align: center;
}
.btns {
text-align: center;
}
.btns button {
width: 120px;
height: 35px;
margin: 0 20px;
}
</style>