0👍
✅
ok i fix it by myself the code even it’s a computed function, inspired by this template : Vue.js proper random ordering of v-for loop
computed: {
randomList(){
var currentIndex = this.postList.length;
var temporaryValue;
var randomIndex;
var myRandomizedList;
// Clone the original array into myRandomizedList (shallow copy of array)
myRandomizedList = this.postList.slice(0)
// Randomize elements within the myRandomizedList - the shallow copy of original array
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = myRandomizedList[currentIndex];
myRandomizedList[currentIndex] = myRandomizedList[randomIndex];
myRandomizedList[randomIndex] = temporaryValue;
}
// Return the new array that has been randomized
return myRandomizedList;
}
}
Source:stackexchange.com