需求: 新内容出现时滚到到底端
1 定义js钩子代码
const Hooks = {}
Hooks.Scroll = {
updated () {
this.el.scrollTop = this.el.scrollHeight
},
mounted () {
this.el.scrollTop = this.el.scrollHeight
}
}
const liveSocket = new LiveSocket('/live', Socket, { hooks: Hooks })
2 在 html 元素上引用钩子
<div phx-hook="Scroll">
很简单地实现了对js 代码的调用.
发表回复