I have a component that looks like this.
export default {
name: "ImagesGallery",
data () {
return {
activeImageIndex: 0,
};
},
}
This specific component serves as an image gallery. I now have another component where I need to make a reference to the activeImageIndex.
<template>
<div>
<images-gallery ref="gallery">
</div>
</template>
export default {
name: "AnotherComponent",
components: {
ImagesGallery,
},
data () {
return {
imageIndex: null, // My intention is for this to point to the images gallery index.
};
},
}
The Goal:
What I am aiming for is to have the "imageIndex" in the other component act as a direct reference to the "activeImageIndex" of the ImagesGallery component. Whenever I update "imageIndex", the value of the gallery index should also change accordingly.
I attempted to set imageIndex: this.$refs.gallery.activeImageIndex in the data function, but it seems that it does not work in this particular scenario.