V
V
Vladimir Golub2020-09-24 15:50:42
Vue.js
Vladimir Golub, 2020-09-24 15:50:42

Why is there a problem with ref when importing into components?

I import the component:

...
    components: {
      MainSection: () => import('@/components/pages/sections/MainSection'),
...


Inside it, when accessing ref in mounted, it produces undefined.
Works only through:
setTimeout(() => {
        console.log(this.$refs.screenImg);
      }, 0);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2020-09-24
@RazerVG

https://ru.vuejs.org/v2/api/#ref

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.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question