2

I have a list created by v-for and wrapped by md-scrollbar.

<md-content class="md-scrollbar"> <div v-for="(msg, index) of list" :key="index"> {{msg}} </div> </md-content> 

After list changed, I wish the scrollbar scroll to the bottom. So need to listen to element updated event or the scrollbar scrollHeight changed event. How to listen to certain DOM element's property is changed?

BTW I can't move the scroll after list changed logic because the new element hasn't been rendered at that moment yet, the height of md-scrollbar didn't update.

2 Answers 2

1

Since you need the updated dom, you could use Vue.nextTick (after list data update) :

Vue.nextTick(function () { // DOM updated }) 
Sign up to request clarification or add additional context in comments.

1 Comment

btw. in my case using in .vue, shall be this.$nextTick(...)
0

use watch to watch list and react accordingly

e.g.

var vm = new Vue({ data: { c: { b: 2 }, }, watch: { c: { handler: function(val, oldVal) { window.scrollTo(0,document.body.scrollHeight); }, deep: true } } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.