A
A
Artemio952021-06-09 16:12:53
Vue.js
Artemio95, 2021-06-09 16:12:53

Why does the computed property give an error when outputting to a template?

Is computed

sliderHeight() {
            return this.$refs.slide[this.sliderActive - 1].clientHeight
        }

It counts everything perfectly, shows the number in devtools. But I should try to display in the template
:style="{
                        left: sliderOffsetLeft,
                        height: sliderHeight + 'px'
                    }"

That is a bunch of errors in the console and computed itself - "(error during evaluation)"
What could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-06-09
@Artemio95

Someone inattentively read the documentation :

An important note about link registration time: since links are created by the render function, you won't be able to use them on initial render - they don't exist yet! Also, the $refs object is not reactive, so don't try to use it in data binding templates.

Accordingly, when you try to read something from $refs, you get undefined, and an attempt to read a property from udnefined - yes, ends with an error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question