vue 获取元素和jQuery不一样,当然也也可以用原生javascript获取dom 元素
通过 ref 获取到元素

<div ref="chat_scoll"></div>
mounted() {
  this.watchScoll()
}
watchScoll() {
   console.log(this.$refs.chat_scoll, 'watchScoll')
   this.$refs.chat_scoll.$el.addEventListener('scroll', this.handleScroll, true)
   //this.$refs.chat_scoll.$el.scrollTop = 1000

  },
  handleScroll(e) {
     console.log('handleScroll', e, e.target.scrollTop, e.target.scrollHeight, e.target.offsetHeight)
  }

标签: none

添加新评论