1

I want to perform a task (scrolling to bottom, since new elements where added) after a view has been updated by vue.

Here is my code:

export default {
    mounted() {
        this.connect();
    },
    connection: null,
    methods: {
        connect: function () {
            ...
        },
        onMessage: function (msg) {

            this.messages.push(msg);
            this.scrollDown();

            return true;
        }, 
        scrollDown: function () {
            $("html, body").animate({
                'scrollTop': $(this).offset().top
            }, 100);
        }

As you can see, the this.scrollDown(); is invoked after this.messages.push(msg);, so since the view is not updated immediately the scroll is not well performed. How is it supposed to be made?

1
  • 1
    It sounds like you want to perform this in the updated event? Commented Jul 26, 2017 at 22:50

1 Answer 1

4

Try waiting for the DOM to be updated using:

this.$nextTick(function () {
  this.scrollDown();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.