L
L
lillianfisher2021-05-01 09:29:53
Vue.js
lillianfisher, 2021-05-01 09:29:53

How to get element inside v-bind?

Hello, I have But I need to access the element. Ie analogue el. How can I do this... v-bind:style="height: el.firstChild.scrollHeight"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-05-01
@Aetae

To begin with, you should not climb inside the child component from the parent component. Never. The child component is a black box. You don’t know if there is anything in it at all firstChildand what it has with it scrollHeight. You don’t know , I say, even if they themselves wrote that component. This is the basis of the component approach: the contents of any component can be completely rewritten without affecting parent components dependent on it. Any control is done via props, events (and, in special cases, documented public methods and properties accessed via ref).
In this case, you need to make a wrapper component for the child (or fix it yourself), or by adding a property likeset-height-by-child, which will control this behavior, or, if you need to work with this height from the outside, send an event from it like when , when changing the screen size and other possible cases. @emit('scroll-height-changed', scrollHeight)mounted

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question