Vue method scroll div to top

后端 未结 5 1034
离开以前
离开以前 2021-01-18 06:20

I am learning vue. I have the following method where I add a chat message to a div with id=\"toolbar-chat\". This div allows scrolling on y axis an

5条回答
  •  时光取名叫无心
    2021-01-18 07:04

    This is old, but for someone who want to find solution like me:

    addMessage(message) {
        this.messages.unshift(message);
        this.$nextTick(() => {
            // block: 'end' will scroll to top of element instead of bottom
            this.$refs.toolbarChat.$el.scrollIntoView({ block: 'end', scrollBehavior: 'smooth' });
        });
    
        axios.post(chat_send_route, message)
        .then(response => {
            console.log(response.data);
        });
    
    }
    

提交回复
热议问题