需求: 新內容出現時滾到到底端html
1 定義js鉤子代碼this
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 元素上引用鉤子code
<div phx-hook="Scroll">
很簡單地實現了對js 代碼的調用.htm