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]-Auto-import VueJs components while coding at SublimeText
- [Vuejs]-Adding vue js dynamic form elements in a specific div
Source:stackexchange.com