アイテムのスワップ機能は、4つの商品をランダムに表示します。
/* 换一换*/
change() {
this.recommendItems = this.getRandomArrayElements(this.recommendlist, 4)
},
/* 随机获取数组中的数据*/
getRandomArrayElements(arr, count) {
var shuffled = arr.slice(0),
i = arr.length,
min = i - count,
temp, index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
},