Answer the question
In order to leave comments, you need to log in
How to hide a block in one component on click of a button in another vue component?
Good afternoon.
Tell. There is a button in the menu component. How to hide a div that is in another component when clicking on a button?
Both components are registered locally on the same page.
Thank you.
Answer the question
In order to leave comments, you need to log in
parent component:
<component-one v-on:click-some-button="hideBlockkInOtherComponent"></component-one>
<component-two ref="othercomponent"></component-two>
methods: {
hideBlockkInOtherComponent () {
this.$refs.othercomponent.hideBlock();
}
}
<div><button v-on:click="sendClickForParent">click</button></div>
methods: {
sendClickForParent () {
this.$emit('click-some-button');
}
}
<div>
<div v-if="showBlock">my block</div>
</div>
data () {
return {
showBlock: true,
};
},
methods: {
hideBlock () {
this.showBlock = false;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question