需求: 新内容出现时滚到到底端
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 代码的调用.