<div class="lunbo" @mouseenter="clear" @mouseleave="run">
<div class="img">
<img :src="dataList[currentIndex]" alt="" />
</div>
</div>
data() {
return {
dataList: [
require('../assets/progressbar/p01.jpg'),
require('../assets/progressbar/p02.jpg'),
require('../assets/progressbar/p03.jpg'),
require('../assets/progressbar/p04.jpg')
],
currentIndex: 0, // 默认显示图片
timer: null,// 定时器
},
created() {
this.run()
},
methods: {
gotoPage(index) {
this.currentIndex = index
},
next() {
if (this.currentIndex === this.dataList.length - 1) {
this.currentIndex = 0
} else {
this.currentIndex++
}
},
up() {
if (this.currentIndex === 0) {
this.currentIndex = this.dataList.length - 1
} else {
this.currentIndex--
}
},
clear() {
clearInterval(this.timer)
},
// 定时器
run() {
this.timer = setInterval(() => {
this.next()
}, 400)
}
}
每次我轮播图片时,整个数据大屏都会卡顿,具体代码修改分析一下