Когда вы создаете свой компонент с этим:
export default {
name: "app",
data() {
return {
images: [
bulma,
bootstrap,
css3,
html5,
illustrator,
js,
photoshop,
vue,
webpack
],
idx: Math.floor(Math.random() * this.images.length),
randomImage: this.images[this.idx]
};
}
};
this.images
(или this.idx
) еще не определено.Вы должны установить значение (например, null
) на randomImage
, затем установить фактическое значение на created
hook:
export default {
name: "app",
data() {
return {
images: [
bulma,
bootstrap,
css3,
html5,
illustrator,
js,
photoshop,
vue,
webpack
],
idx: null,
randomImage: null
};
},
created() {
this.idx = Math.floor(Math.random() * this.images.length)
this.randomImage = this.images[this.idx]
}
};