Answer the question
In order to leave comments, you need to log in
How to recalculate the height of elements in a list without using refs?
Is computed
sliderHeight() {
return this.$refs.slide[this.sliderActive - 1].clientHeight
}
:style="{
left: sliderOffsetLeft,
height: sliderHeight + 'px'
}"
Answer the question
In order to leave comments, you need to log in
1. computed
will not be recalculated when updating refs or dom-values. It works with reactive data.
2. Refs are only available after the relevant items are loaded (obviously), and you seem to access them earlier.
Bottom line: remove this code from computed
and place it in mounted
, manually assigning values to the variable in data
. Don't forget to add default values, and also update them if necessary (by the resize event or something else that can affect these sizes).
PS In most cases, what you are trying to solve with such code is done in css.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question