File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
packages/taro-components/src/components/image Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -41,12 +41,12 @@ export class Image implements ComponentInterface {
4141 private imgRef : HTMLImageElement
4242
4343 componentDidLoad ( ) {
44- if ( ! this . lazyLoad ) return
44+ if ( ! this . lazyLoad || ! this . imgRef ) return
4545
4646 const lazyImg = new IntersectionObserver ( entries => {
4747 // 异步 api 关系
4848 if ( entries [ entries . length - 1 ] . isIntersecting ) {
49- lazyImg . unobserve ( this . imgRef )
49+ this . imgRef && lazyImg . unobserve ( this . imgRef )
5050 this . didLoad = true
5151 }
5252 } , {
@@ -57,6 +57,9 @@ export class Image implements ComponentInterface {
5757 }
5858
5959 imageOnLoad ( ) {
60+ // 防止组件已卸载或 img 已被移除时 ref 为 null(如列表滚动、src 清空、lazyLoad 时序等)
61+ if ( ! this . imgRef ) return
62+
6063 const {
6164 width,
6265 height,
You can’t perform that action at this time.
0 commit comments