0๐
I created sample Parent and Child components that implement the functionality you describe.
Parent.vue
<template>
<div class="parent">
<h3>Parent.vue</h3>
<div class="row">
<div class="col-md-6">
<div v-if="showDiv">Div for child to show/hide</div>
</div>
</div>
<child @toggle-parent-div="toggleDiv" />
</div>
</template>
<script>
import Child from './Child.vue'
export default {
components: {
Child
},
data() {
return {
showDiv: true
}
},
methods: {
toggleDiv() {
this.showDiv = !this.showDiv;
}
}
}
</script>
Child.vue
<template>
<div class="child">
<hr>
<h3>Child.vue</h3>
<div class="row">
<div class="col-md-6">
<button class="btn btn-secondary" @click="toggleParentDiv">Click to toggle parent div</button>
</div>
</div>
</div>
</template>
<script>
export default {
methods: {
toggleParentDiv() {
this.$emit('toggle-parent-div');
}
}
}
</script>
- [Vuejs]-$Emit is passing "undefined" property instead of an int property?
- [Vuejs]-Javascript/vue.js async/await and .then (promise) not waiting until completion of fetch in login function
Source:stackexchange.com