Answer the question
In order to leave comments, you need to log in
How to make a dynamic modal in vue?
I just started to study vue and now there is such a task, there is an array with data, these are projects
data() {
return {
projects: [
{
id: '1',
src: 'siemens.jpg',
title: 'Siemens'
},
{
id: '2',
src: 'nokia.jpg',
title: 'Nokia'
},
..............
<div v-for="item in projects" :key="item.id" @click="showModal">
<img :src="require('@/assets/portfolio/' + item.src)" :alt="item.title" loading="lazy" width="200" height="200">
<p>{{item.title}}</p>
</div>
Answer the question
In order to leave comments, you need to log in
If this is only for one page, then you can do without a component. Just add a modal div to the page that will show up when you select a project. As long as selectedProject has a value cast to false (eg null) - that div is hidden. We wrote down a link to the project there - the div was activated.
<div v-show="selectedProject" class="modal">
...
{{ selectedProject.title }}
...
</div>
https://ru.vuejs.org/v2/examples/modal.html
And throw data into it through props.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question