I am working on a web application using Vue2
and BootstrapVue
, and I have a series of 6 elements (of which I will only upload 3 here, for practical reasons), all aesthetically equal, but with different content, rendereados by a v-for
. To them I am adding a modal with Bootstrap, which could generate it in the same way, but the detail is that I do not want to load the page with the 6 manners in the background. I want to generate them at the moment of clicking on the "Learn More" button and that the information corresponding to that element of the array is shown in my file .vue
.
I do not know how to do to relate by a index
to the element which I want to show the information.
Below I attach my code:
Component.html
<div id="blocks">
<b-container>
<div class="cards">
<div class="card" v-for="card in cards">
<img :src="card.image" :alt="card.mainTitle">
<div class="card-content">
<h5>{{card.mainTitle}}</h5>
<p>{{card.text}}</p>
<a href="javascript:void(0)" @click="showModal">Learn More</i></a>
</div>
</div>
</div>
</b-container>
<b-modal ref="modal" centered hide-footer>
<div class="d-block text-center">
<h3>{{cards.mainTitle}}</h3>
<p>{{modalText}}</p>
</div>
</b-modal>
</div>
Component.vue
export default {
name: 'benefits',
data () {
return {
cards: [
{
image: require('../../assets/image1.jpg'),
mainTitle: 'Title1',
text: 'Text1',
modalText: 'Modal text content1'
},
{
image: require('../../assets/image2.jpg'),
mainTitle: 'Title2',
text: 'Text2',
modalText: 'Modal text content2'
},
{
image: require('../../assets/image3.jpg'),
mainTitle: 'Title3',
text: 'Text3',
modalText: 'Modal text content3'
}
]
}
},
methods: {
showModal () {
this.$refs.modal.show()
},
hideModal () {
this.$refs.modal.hide()
}
}
}