Skip to content

Commit 368af43

Browse files
huxinhaianlyyao
andauthored
修复image组件图片懒加载失效 (#3036)
* 修复image组件图片懒加载失效 * fix(image): 修复image组件图片懒加载失效 * test: update snapshots --------- Co-authored-by: hxh <1047739781> Co-authored-by: anlyyao <anly_yaw@163.com>
1 parent 0ae794e commit 368af43

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

src/image-viewer/__test__/__snapshots__/index.test.js.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ exports[`image-viewer :base 1`] = `
5050
<wx-image
5151
ariaHidden="{{true}}"
5252
ariaLabel=""
53-
class="class t-class t-image t-image--shape-square"
54-
hidden="{{true}}"
53+
class="class t-class t-image t-image--shape-square t-image--lazy"
5554
id="image"
5655
lazyLoad="{{true}}"
5756
mode="aspectFit"
@@ -115,8 +114,7 @@ exports[`image-viewer :base 2`] = `
115114
<wx-image
116115
ariaHidden="{{true}}"
117116
ariaLabel=""
118-
class="class t-class t-image t-image--shape-square"
119-
hidden="{{true}}"
117+
class="class t-class t-image t-image--shape-square t-image--lazy"
120118
id="image"
121119
lazyLoad="{{true}}"
122120
mode="aspectFit"
@@ -180,8 +178,7 @@ exports[`image-viewer :base 3`] = `
180178
<wx-image
181179
ariaHidden="{{true}}"
182180
ariaLabel=""
183-
class="class t-class t-image t-image--shape-square"
184-
hidden="{{true}}"
181+
class="class t-class t-image t-image--shape-square t-image--lazy"
185182
id="image"
186183
lazyLoad="{{true}}"
187184
mode="aspectFit"

src/image/__test__/__snapshots__/index.test.js.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ exports[`image :base 1`] = `
4646
<wx-image
4747
ariaHidden="{{true}}"
4848
ariaLabel=""
49-
class="class t-class t-image t-image--shape-square"
50-
hidden="{{true}}"
49+
class="class t-class t-image t-image--shape-square t-image--lazy"
5150
id="image"
5251
lazyLoad="{{false}}"
5352
mode="scaleToFill"
@@ -71,8 +70,7 @@ exports[`image :success 1`] = `
7170
<wx-image
7271
ariaHidden="{{false}}"
7372
ariaLabel=""
74-
class="class t-class t-image t-image--shape-square"
75-
hidden="{{false}}"
73+
class="class t-class t-image t-image--shape-square "
7674
id="image"
7775
lazyLoad="{{false}}"
7876
mode="heightFix"

src/image/image.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
@image-loading-color: var(--td-image-loading-color, @text-color-placeholder);
66
@image-round-radius: var(--td-image-round-radius, @radius-default);
77

8+
:host {
9+
position: relative;
10+
}
11+
812
.@{prefix}-image {
913
color: @image-color;
1014
vertical-align: top;
@@ -27,6 +31,12 @@
2731
height: 100%;
2832
}
2933

34+
&--lazy {
35+
position: absolute;
36+
top: 0;
37+
z-index: -1;
38+
}
39+
3040
&--shape {
3141
&-circle {
3242
border-radius: 50%;

src/image/image.wxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
<!-- 图片 -->
3838
<image
3939
id="{{tId||'image'}}"
40-
hidden="{{isLoading || isFailed}}"
41-
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}--shape-{{shape}}"
40+
wx:if="{{ !isFailed }}"
41+
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}--shape-{{shape}} {{isLoading ? classPrefix + '--lazy' : ''}}"
4242
src="{{src}}"
4343
style="{{_._style([innerStyle, style, customStyle])}}"
4444
mode="{{mode}}"

0 commit comments

Comments
 (0)