I'm trying to save scroll position of vue-instantsearch results in session storage so that when you click on a result and then the back button, the browser returns to that point of the page after the results have been loaded.
Because at the moment, you get returned to a place in the page where you were before, but before the results load, so it's much further down the page.
I thought the Vue mounted lifecycle option was what I needed and I'm doing this:
import algoliasearch from 'algoliasearch/lite';
import { routing } from '@/routing';
import Product from '@/components/Product.vue';
export default {
components: {
Product
},
data() {
return {
searchClient: algoliasearch(xxxx, xxxx),
routing: xxxx,
selectedIndex: xxxx
};
},
computed: {},
methods: {},
mounted: function () {
this.$nextTick(function () {
window.scrollTo({
top: sessionStorage.scroll, // this is set elsewhere
left: 0,
behavior: 'smooth'
});
});
}
};
But even with that, after clicking back from a search result, you still end up near the bottom of the page.
Is mounted not what I need?