Answer the question
In order to leave comments, you need to log in
How to change the style in a component in Vue.js when clicking on an element in another component?
The first component has a link, when clicked, a class is added or removed to some element
<a href="#" @click="showMobileMenu = !showMobileMenu">
how to make this class apply to an element from another component:<div class="asd" :class="{ active: showMobileMenu }" >
Answer the question
In order to leave comments, you need to log in
If this component is higher - $emit
an event.
If this component is lower - through props
.
If these components are widely spaced, but are always logically in the same parent - provide
in the parent and inject
in both components.
If they are connected by a common logic - a separate reactive object
Vue.observable
/ Vue.reactive
and, accordingly, import
in both components.
And finally, if the components are not connected in any way and there are many such situations - Vuex .)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question