Skip to content

Commit c6f6818

Browse files
童皓童皓
authored andcommitted
u-image doc提示
1 parent 51377ce commit c6f6818

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

uview-ui/components/u-image/u-image.vue

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<template>
2-
<view
3-
class="u-image"
4-
@tap="onClick"
5-
:style="[wrapStyle, backgroundStyle]"
6-
>
2+
<view class="u-image" @tap="onClick" :style="[wrapStyle, backgroundStyle]">
73
<image
84
v-if="!isError"
95
:src="src"
@@ -13,26 +9,58 @@
139
:lazy-load="lazyLoad"
1410
class="u-image__image"
1511
:style="{
16-
borderRadius: shape == 'circle' ? '50%' : $u.addUnit(borderRadius),
12+
borderRadius: shape == 'circle' ? '50%' : $u.addUnit(borderRadius)
1713
}"
1814
></image>
19-
<view v-if="showLoading && loading" class="u-image__loading" :style="{
20-
borderRadius: shape == 'circle' ? '50%' : $u.addUnit(borderRadius),
21-
backgroundColor: this.bgColor
22-
}">
15+
<view
16+
v-if="showLoading && loading"
17+
class="u-image__loading"
18+
:style="{
19+
borderRadius: shape == 'circle' ? '50%' : $u.addUnit(borderRadius),
20+
backgroundColor: this.bgColor
21+
}"
22+
>
2323
<slot v-if="$slots.loading" name="loading" />
2424
<u-icon v-else :name="loadingIcon"></u-icon>
2525
</view>
26-
<view v-if="showError && isError && !loading" class="u-image__error" :style="{
27-
borderRadius: shape == 'circle' ? '50%' : $u.addUnit(borderRadius),
28-
}">
26+
<view
27+
v-if="showError && isError && !loading"
28+
class="u-image__error"
29+
:style="{
30+
borderRadius: shape == 'circle' ? '50%' : $u.addUnit(borderRadius)
31+
}"
32+
>
2933
<slot v-if="$slots.error" name="error" />
3034
<u-icon v-else :name="errorIcon"></u-icon>
3135
</view>
3236
</view>
3337
</template>
3438

3539
<script>
40+
/**
41+
* Image 图片
42+
* @description 此组件为uni-app的image组件的加强版,在继承了原有功能外,还支持淡入动画、加载中、加载失败提示、圆角值和形状等。
43+
* @tutorial https://uviewui.com/components/image.html
44+
* @property {String} src 图片地址
45+
* @property {String} mode 裁剪模式,见官网说明
46+
* @property {String | Number} width 宽度,单位任意,如果为数值,则为rpx单位(默认100%)
47+
* @property {String | Number} height 高度,单位任意,如果为数值,则为rpx单位(默认 auto)
48+
* @property {String} shape 图片形状,circle-圆形,square-方形(默认square)
49+
* @property {String | Number} border-radius 圆角值,单位任意,如果为数值,则为rpx单位(默认 0)
50+
* @property {Boolean} lazy-load 是否懒加载,仅微信小程序、App、百度小程序、字节跳动小程序有效(默认 true)
51+
* @property {Boolean} show-menu-by-longpress 是否开启长按图片显示识别小程序码菜单,仅微信小程序有效(默认 false)
52+
* @property {String} loading-icon 加载中的图标,或者小图片(默认 photo)
53+
* @property {String} error-icon 加载失败的图标,或者小图片(默认 error-circle)
54+
* @property {Boolean} show-loading 是否显示加载中的图标或者自定义的slot(默认 true)
55+
* @property {Boolean} show-error 是否显示加载错误的图标或者自定义的slot(默认 true)
56+
* @property {Boolean} fade 是否需要淡入效果(默认 true)
57+
* @property {Boolean} webp 只支持网络资源,只对微信小程序有效(默认 false)
58+
* @property {String | Number} duration 搭配fade参数的过渡时间,单位ms(默认 500)
59+
* @event {Function} click 点击图片时触发
60+
* @event {Function} error 图片加载失败时触发
61+
* @event {Function} load 图片加载成功时触发
62+
* @example <u-image width="100%" height="300rpx" :src="src"></u-image>
63+
*/
3664
export default {
3765
props: {
3866
// 图片地址
@@ -140,7 +168,7 @@ export default {
140168
style.borderRadius = this.shape == 'circle' ? '50%' : this.$u.addUnit(this.borderRadius);
141169
// 如果设置圆角,必须要有hidden,否则可能圆角无效
142170
style.overflow = this.borderRadius > 0 ? 'hidden' : 'visible';
143-
if(this.fade) {
171+
if (this.fade) {
144172
style.opacity = this.opacity;
145173
style.transition = `opacity ${Number(this.durationTime) / 1000}s ease-in-out`;
146174
}
@@ -165,7 +193,7 @@ export default {
165193
this.$emit('load');
166194
// 如果不需要动画效果,就不执行下方代码,同时移除加载时的背景颜色
167195
// 否则无需fade效果时,png图片依然能看到下方的背景色
168-
if(!this.fade) return this.removeBgColor();
196+
if (!this.fade) return this.removeBgColor();
169197
// 原来opacity为1(不透明,是为了显示占位图),改成0(透明,意味着该元素显示的是背景颜色,默认的灰色),再改成1,是为了获得过渡效果
170198
this.opacity = 0;
171199
// 这里设置为0,是为了图片展示到背景全透明这个过程时间为0,延时之后延时之后重新设置为duration,是为了获得背景透明(灰色)
@@ -177,8 +205,8 @@ export default {
177205
this.opacity = 1;
178206
setTimeout(() => {
179207
this.removeBgColor();
180-
}, this.durationTime)
181-
}, 50)
208+
}, this.durationTime);
209+
}, 50);
182210
},
183211
// 移除图片的背景色
184212
removeBgColor() {
@@ -203,7 +231,8 @@ export default {
203231
height: 100%;
204232
}
205233
206-
&__loading, &__error {
234+
&__loading,
235+
&__error {
207236
position: absolute;
208237
top: 0;
209238
left: 0;

0 commit comments

Comments
 (0)