I have a component as follows.
export default {
name: "ImagesGallery",
data () {
return {
activeImageIndex: 0,
};
},
}
This component is a gallery of images. Now I have another component in which I need to refer to the activeImageIndex.
<template>
<div>
<images-gallery ref="gallery">
</div>
</template>
export default {
name: "AnotherComponent",
components: {
ImagesGallery,
},
data () {
return {
imageIndex: null, // I want this to refer to the images gallery index.
};
},
}
What I want to achieve:
I want the "imageIndex" of the other component to be a reference to the "activeImageIndex" of the ImagesGallery component. If I modify "imageIndex", also the value of the gallery index should change.
I tried to assign imageIndex: this.$refs.gallery.activeImageIndex in the data function but obviously it doesn't works in this context.