I have a v-for list of items that are based on list stored in Vuex. I want it so that the list automatically scrolls to the bottom every time a new item is added. I figured the scrolling part out using this: Scroll to bottom of div?
The pseudocode is the following:
addItem(){
dispatch vuex event to add item
scroll to bottom of list
}
The issue I'm running into is that Vue seems to be updating the v-for list after the list is scrolled to the bottom, meaning that the list is always scrolled to the second to last item, instead of the last.
I fixed it by using a setTimout()
to wait 10ms, but it feels a little hacky. Is there a better way to trigger the scrollToBottom()
code on v-for list update?