H
H
hackuun2018-07-15 17:52:06
Vue.js
hackuun, 2018-07-15 17:52:06

How to access the same ref for multiple elements?

There is a component in which ref is assigned

<video ref="player">
   ...
</video>

This component 1) is used multiple times on 1 page; 2) used on another page
If there are no problems with the first scenario (I believe the view itself recognizes where which ref is from the array), then the second problem is this: when moving from the page where this component was used with ref to another page where the same component is used with with the same ref i get the error
Uncaught TypeError: Cannot read property 'getBoundingClientRect' of undefined

I address so
this.$refs.player.getBoundingClientRect().top
What to do or make in that case?
The usecase is the component that I want to listen to when it appears in the viewport. Can it come from the other side?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question