fix: 🐛 组件mounted钩子执行时 页面可能已经onload 导致 滚动校验不成功

This commit is contained in:
王珏 2020-09-04 10:03:17 +08:00
parent 5bdf913cd4
commit 93d4267567
1 changed files with 1 additions and 2 deletions

View File

@ -128,7 +128,7 @@ export default {
mounted () { mounted () {
// 初始化判断 // 初始化判断
// 默认判断父元素和子元素的大小,以确定初始情况是否显示滚动 // 默认判断父元素和子元素的大小,以确定初始情况是否显示滚动
window.addEventListener('load', this.checkScroll) this.checkScroll()
// 全局窗口变化监听判断父元素和子元素的大小从而控制isScroll的开关 // 全局窗口变化监听判断父元素和子元素的大小从而控制isScroll的开关
this.throttledCheckScroll = throttle(this.checkScroll, 300) this.throttledCheckScroll = throttle(this.checkScroll, 300)
window.addEventListener('resize', this.throttledCheckScroll) window.addEventListener('resize', this.throttledCheckScroll)
@ -136,6 +136,5 @@ export default {
beforeDestroy () { beforeDestroy () {
// 取消监听 // 取消监听
window.removeEventListener('resize', this.throttledCheckScroll) window.removeEventListener('resize', this.throttledCheckScroll)
window.removeEventListener('load', this.checkScroll)
} }
} }