I have two sibling components where one relies on the other for an event to happen. In this case, I want to apply this styling - marginTop = "-20px";
to the div of one component when the length of an input inside another component is more than 0 characters.
Whether it be props, slots, refs or events, I'm still not sure what fits this use case (I'm very new to Vue). I'm also not sure if I can even pass data between these two sibling components directly or if I have to pass from one child to the parent and then to the other child.
What I'm currently attempting to do is to simply grab the element I want to apply the style to (in the vanilla JS way) and have the method invoked when the aforementioned condition becomes true (all in the same component).
// Component trying to style the element
<ais-state-results v-if="input.length > 0">
// Component trying to style the element
mounted() {
this.positionSecondaryContent();
},
methods: {
positionSecondaryContent() {
const secondaryContent = document.querySelector('.secondary-content');
secondaryContent.style.marginTop = "-20px";
}
},
// Component that has the element to be styled
<template>
<div class="secondary-content">
<TheWordOfTheDay />
<SuggestTranslationForm />
</div>
</template>
Aside from not knowing if I really should be communicating with other components, I'm not sure what to write in the ais-state-results
component instance above to attach it to my method and then have the method run as soon as the condition is met.
Comments
Post a Comment