用vue写出四个按钮每个按钮匹配一个勾选框。第一行延时0.1秒触发。第二行0.2秒依次类推。然后有个开始按钮。勾选后按钮后。比如勾选了第一行。第三行。分别在0.1秒点击下第一行按钮。每0.3秒点击下第三行按钮并出现点击动画或者能直观的看到已经点击了。开始按钮点击后变成停止按钮并变色
时间: 2023-08-21 17:03:28 浏览: 77
可以参考以下代码实现:
```
<template>
<div>
<div class="row">
<button v-for="(checked, index) in row1" :key="index" @click="handleButtonClick(1, index)" :disabled="!checked">{{ checked ? '已勾选' : '勾选' }}</button>
<div class="checkbox" v-if="row1Checked"><i class="fas fa-check"></i></div>
</div>
<div class="row">
<button v-for="(checked, index) in row2" :key="index" @click="handleButtonClick(2, index)" :disabled="!checked">{{ checked ? '已勾选' : '勾选' }}</button>
<div class="checkbox" v-if="row2Checked"><i class="fas fa-check"></i></div>
</div>
<div class="row">
<button v-for="(checked, index) in row3" :key="index" @click="handleButtonClick(3, index)" :disabled="!checked">{{ checked ? '已勾选' : '勾选' }}</button>
<div class="checkbox" v-if="row3Checked"><i class="fas fa-check"></i></div>
</div>
<div class="row">
<button v-for="(checked, index) in row4" :key="index" @click="handleButtonClick(4, index)" :disabled="!checked">{{ checked ? '已勾选' : '勾选' }}</button>
<div class="checkbox" v-if="row4Checked"><i class="fas fa-check"></i></div>
</div>
<button @click="startOrStop">{{ isStarted ? '停止' : '开始' }}</button>
</div>
</template>
<script>
export default {
data() {
return {
row1: [false, false, false, false],
row2: [false, false, false, false],
row3: [false, false, false, false],
row4: [false, false, false, false],
row1Checked: false,
row2Checked: false,
row3Checked: false,
row4Checked: false,
isStarted: false,
intervalId: null
}
},
methods: {
handleButtonClick(row, index) {
switch (row) {
case 1:
this.row1[index] = !this.row1[index]
break
case 2:
this.row2[index] = !this.row2[index]
break
case 3:
this.row3[index] = !this.row3[index]
break
case 4:
this.row4[index] = !this.row4[index]
break
}
},
startOrStop() {
if (this.isStarted) {
clearInterval(this.intervalId)
this.isStarted = false
} else {
this.isStarted = true
let row1Index = 0
let row2Index = 0
let row3Index = 0
let row4Index = 0
this.intervalId = setInterval(() => {
if (this.row1[row1Index]) {
this.row1Checked = true
setTimeout(() => {
this.row1Checked = false
}, 300)
}
if (this.row2[row2Index]) {
this.row2Checked = true
setTimeout(() => {
this.row2Checked = false
}, 300)
}
if (this.row3[row3Index]) {
this.row3Checked = true
setTimeout(() => {
this.row3Checked = false
}, 300)
}
if (this.row4[row4Index]) {
this.row4Checked = true
setTimeout(() => {
this.row4Checked = false
}, 300)
}
row1Index = (row1Index + 1) % this.row1.length
row2Index = (row2Index + 1) % this.row2.length
row3Index = (row3Index + 1) % this.row3.length
row4Index = (row4Index + 1) % this.row4.length
}, 100)
}
}
}
}
</script>
<style>
.row {
display: flex;
align-items: center;
margin-bottom: 10px;
}
button {
margin-right: 10px;
}
.checkbox {
width: 20px;
height: 20px;
background-color: #ccc;
display: flex;
justify-content: center;
align-items: center;
margin-left: 10px;
}
.checkbox i {
color: #fff;
}
</style>
```
这里使用了一个定时器,每隔一定时间检查哪些按钮被勾选,然后模拟点击,同时也显示了点击动画。开始/停止按钮使用了一个布尔类型的变量 `isStarted` 来控制状态,同时也使用了一个定时器来定期执行点击操作。
阅读全文