I have a component TopBar.vue
and I'm trying to open a modal (a child component Feedback.vue
).
How do I bind the showFeedbackModal
property between both components?
I want to make it so that when you click the <a>
tag with @click="showFeedbackModal = true
the value true
gets passed to the <feedback>
component and the modal is shown.
TopBar.vue (Main)
<template>
<div>
<section class="top-bar level">
<div class="level-left">
...
<ul class="level-item">
<li><a @click="showFeedbackModal = true"><i class="fa fa-envelope-open-o" aria-hidden="true"></i> Beta Feedback</a></li>
</ul>
</div>
...
</section>
<feedback :showFeedbackModal="showFeedbackModal"></feedback>
</div>
</template>
<script>
export default {
data() {
return {
showFeedbackModal: false
}
}
}
</script>
Feedback.vue (modal)
<template>
<div>
<div v-if="showModal" class="modal is-active">
<div class="modal-background" @click="showModal = false"></div>
<div class="modal-content">
<div class="box">
This is the feedback content
</div>
</div>
<button class="modal-close" @click="showModal = false"></button>
</div>
</div>
</template>
<script>
export default {
props: ['showFeedbackModal'],
data() {
return {
showModal: false
}
},
beforeMount() {
this.showModal = this.showFeedbackModal;
}
}
</script>