This question already has an answer here:
I have a Vue JS project that displays random elements in a modal when the user clicks on a button. It currently displays random elements but I have noticed that it repeats entries as opposed to going through the elements randomly and NOT repeating them.
How would I go about making sure it doesn't repeat entries until it has randomly gone through them all?
Here is what I have so far, the getPlace() method is where the random element code is:
export default {
name: 'home-page',
components: {BaseLayout},
data () {
return {
peopleData: {},
modalShow: false
}
},
methods: {
getPlace: function () {
let keys = Object.keys(peoplesDataJson)
let random = Math.floor(Math.random() * keys.length)
this.placeData = peoplesDataJson[keys[random]]
}
}
}
My Json data looks like:
{
"1": {
"personID": 1,
"person": "Person 1"
},
"2": {
"personID": 2,
"person": "Person 2"
},
"3": {
"personID": 3,
"person": "Person 3"
}
}
Aucun commentaire:
Enregistrer un commentaire