I have a v-for list of items that are derived from a list stored in Vuex. My goal is to ensure that the list automatically scrolls to the bottom each time a new item is added. I managed to implement the scrolling functionality by referring to this helpful resource: Scroll to bottom of div?
The basic idea behind achieving this is as follows:
addItem(){
dispatch a Vuex event to add an item
scroll to the bottom of the list
}
However, I encountered an issue where Vue seems to update the v-for list after the scrolling action takes place. As a result, the list always ends up scrolled to the second to last item instead of the very last one.
To address this issue, I temporarily resolved it by incorporating a setTimeout()
function to introduce a 10ms delay. While this workaround works, it does feel somewhat hacky. Is there a more elegant and efficient way to trigger the scrollToBottom()
function upon updating the v-for list?