Help! I'm trying to randomly display one of these names in my HTML, but I can't seem to make it work:
Vue.component('modal', {
template: '#modal-template',
data: {
items: [
{ name: 'Elena' },
{ name: 'Ares' }
]
}, nowName : "",
created () {
const idx = Math.floor(Math.random() * this.items.length);
this.nowName = this.items[idx]
}
})
I've been struggling with my Vue code. I'm not sure if it's correct and if I can retrieve the random name using {{ nowName }}. I've tried different methods and functions in data, but nothing seems to give me a random result.