M
M
Maxim2021-10-30 20:59:13
Vue.js
Maxim, 2021-10-30 20:59:13

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

1 answer(s)
A
Aetae, 2021-10-30
@Pronchik1

If this component is higher - $emitan event.
If this component is lower - through props.
If these components are widely spaced, but are always logically in the same parent - providein the parent and injectin both components.
If they are connected by a common logic - a separate reactive object
Vue.observable/ Vue.reactiveand, accordingly, importin 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 question

Ask a Question

731 491 924 answers to any question