需要判断i值和数组长度的关系,一旦大于i归0
setInterval((i => (() =>( this.$refs.danmu.render(ret.data[i].avatar,ret.data[i].username,‘参加了‘,ret.data[i].gift_name,1000); i++;)))(0),5000);
setInterval((i => (() =>{ if(i>ret.data.length)i=0; this.$refs.danmu.render(ret.data[i].avatar,ret.data[i].username,‘参加了‘,ret.data[i].gift_name,1000); i++;}))(0),5000);
原文:https://www.cnblogs.com/wangyang0210/p/10168003.html