You need to use accordions.value for accessing the ref value.
https://vuejs.org/guide/essentials/template-refs.html#accessing-the-refs
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Anybody an idea how to get the offsetTop of an element in Vue3 with the composite API? Like this version of Vue2?
goto(refName) { var element = this.$refs[refName]; var top = element.offsetTop; window.scrollTo(0, top); }
i have in my setup():
const accordions = ref([]);
it is filled by elements of a v-for. I could get the proxy out of the array later. But not the offset:
const element = accordions[region]; console.log("Region: " + region); //got the name console.log("Element: ", element); // Proxy of element const top = element.offsetTop; console.log("OffsetTop: " + top); // !!! Undefined window.scrollTo({ top: top, left: 0, behavior: "smooth", });
Please or to participate in this conversation.