循环播放:
用定时器,图片路径后面加随机数
图片闪烁:
图片预加载
下面贴代码:
mounted(){
this.timer= setInterval(()=>{
this.bgGif= require('../../assets/main/bgGif.gif')+'?'+Math.random()//添加随机数
this.loadImage(this.bgGif,this.setImage)
},700)
},
loadImg(url,callback) {
var img = new Image();
img.src = url;
img.onload = function(){//图片预加载
callback(img);
};
},
setImg(img){
this.bgGif="url("+img.src+")"+"no-repeat center -50px/ 92% #152348"
},
// 关闭定时器
destroyed(){
clearInterval(this.timer)
}