Skip to content

Commit

Permalink
修复了加载过程中可能出现 Root label not found 错误的问题 #470
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-yufeng committed Dec 25, 2022
1 parent fed8bf9 commit 7ad10c3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/miniprogram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,27 @@ Component({

if (this.properties.lazyLoad || this.imgList._unloadimgs < this.imgList.length / 2) {
// 设置懒加载,每 350ms 获取高度,不变则认为加载完毕
let height
let height = 0
const callback = rect => {
if (!rect || !rect.height) rect = {}
// 350ms 总高度无变化就触发 ready 事件
if (rect.height === height) {
this.triggerEvent('ready', rect)
} else {
height = rect.height
setTimeout(() => {
this.getRect().then(callback)
this.getRect().then(callback).catch(callback)
}, 350)
}
}
this.getRect().then(callback)
this.getRect().then(callback).catch(callback)
} else {
// 未设置懒加载,等待所有图片加载完毕
if (!this.imgList._unloadimgs) {
this.getRect().then(rect => {
this.triggerEvent('ready', rect)
}).catch(() => {
this.triggerEvent('ready', {})
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/miniprogram/node/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Component({
setTimeout(() => {
this.root.getRect().then(rect => {
this.root.triggerEvent('ready', rect)
}).catch(() => {
this.root.triggerEvent('ready', {})
})
}, 350)
}
Expand Down
13 changes: 9 additions & 4 deletions src/uni-app/components/mp-html/mp-html.vue
Original file line number Diff line number Diff line change
Expand Up @@ -331,24 +331,27 @@ export default {
if (this.lazyLoad || this.imgList._unloadimgs < this.imgList.length / 2) {
// 设置懒加载,每 350ms 获取高度,不变则认为加载完毕
let height
let height = 0
const callback = rect => {
if (!rect || !rect.height) rect = {}
// 350ms 总高度无变化就触发 ready 事件
if (rect.height === height) {
this.$emit('ready', rect)
} else {
height = rect.height
setTimeout(() => {
this.getRect().then(callback)
this.getRect().then(callback).catch(callback)
}, 350)
}
}
this.getRect().then(callback)
this.getRect().then(callback).catch(callback)
} else {
// 未设置懒加载,等待所有图片加载完毕
if (!this.imgList._unloadimgs) {
this.getRect().then(rect => {
this.$emit('ready', rect)
}).catch(() => {
this.$emit('ready', {})
})
}
}
Expand Down Expand Up @@ -397,7 +400,9 @@ export default {
case 'onReady':
this.getRect().then(res => {
this.$emit('ready', res)
}).catch(() => { })
}).catch(() => {
this.$emit('ready', {})
})
break
// 总高度发生变化
case 'onHeightChange':
Expand Down
2 changes: 2 additions & 0 deletions src/uni-app/components/mp-html/node/node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ export default {
setTimeout(() => {
this.root.getRect().then(rect => {
this.root.$emit('ready', rect)
}).catch(() => {
this.root.$emit('ready', {})
})
}, 350)
}
Expand Down

0 comments on commit 7ad10c3

Please sign in to comment.