I have worked on vue2 with a simple demo, there is an array with values, by clicking the button, the array values will be shuffled. However rendering the array in html doesn't change at all after the shuffling.
<template>
<div>
<div @click="random()" > random </div>
{{ selected11.length }}
<div class="flex flex-grow " v-for="(item,index) in selected11" :key="index" >
{{ item }} {{ index }}
</div>
</div>
</template>
<script>
export default {
name: 'Choice',
data() {
return {
selected11:[],
}
},
created() {
this.selected11 = ['A', 'B', 'C', 'D','E'];
},
methods: {
random(){
console.log( 'random',this.selected11 );
this.selected11 = this.shuffle( this.selected11 );
console.log( this.selected11 );
},
shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
}
}
</script>