Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

erizo's avatar
Level 8

Vue 3 keep scrolling position on re-render

Hi all,

I have a vue 3 component It wraps 3 paginated tables

When a user changes page on a table he is scrolled by to the top of the page Pages Index are store in a Pinia Store.

Closest thread I could find is this One

I have stored the YOffset in the local state and to restore the position from a watcher watching my state The YOffset is stored Ok, the CallBAck is called, but not scrolling occurs

const yScroll = ref(0);
watch(
  myStore,
  () => {
    console.log("Re-render scroll to ", yScroll.value);
		 // also tried making callBack  async and call nextTick as in the linked thread
         // used the ''post' flush option as suggested 
      	 // https://vuejs.org/guide/essentials/watchers.html#callback-flush-timing
         //await nextTick();
    window.scroll(0, yScroll.value);
  },
  { deep: true, flush: "post" }
);

any Idea To either restore the Position or prevent the scrool to top on re-render ?

0 likes
1 reply
erizo's avatar
erizo
OP
Best Answer
Level 8

After a bit of searching through the code and doc I guess I am an idiot :

pagination links were plain <a> tags.

So I guess there was a full post back. Vite must be really fast I did not notice that.

Please or to participate in this conversation.