如图所示,需要实现点击换一换,随机切换列表
实现
定义
showActive:[0,1,2,3], //储存需要渲染的索引
list:[], //后台返回的数据列表
JS
replace(){
var a = [];
var j= 0;
while(j<4){
var b = Math.floor((Math.random()*this.showData.activity_list.length));
if(a.indexOf(b)==-1){
a.push(b);
j++;
}
};
this.showActive = a;
}
渲染
<div v-for="(item, index) in showActive" :key="index" > {{list[item].title}} </div>