|
1 | 1 | <frame/> |
2 | 2 |
|
3 | | -# Img 图片 |
| 3 | +# Img 图片 |
4 | 4 |
|
5 | 5 | 增强版的 img 标签,提供多种图片填充模式,支持图片懒加载、加载完成、加载失败 |
6 | 6 |
|
7 | | - |
8 | 7 | ## 基本用法 |
9 | 8 |
|
10 | 9 | 基础用法与原生 image 标签一致,可以设置 `src` 、 `width` 、`height` 等原生属性。 |
|
30 | 29 | const joy = 'data:image/jpeg;base64,...' // 图片文件base64 |
31 | 30 | ``` |
32 | 31 |
|
| 32 | +## 插槽 |
| 33 | + |
| 34 | +使用`loading` `error`插槽设置在图片加载时、加载失败后的展示内容 |
| 35 | + |
| 36 | +```vue |
| 37 | +<template> |
| 38 | + <wd-img :width="100" :height="100" src="https://www.123.com/a.jpg"> |
| 39 | + <template #error> |
| 40 | + <view class="error-wrap"> |
| 41 | + 加载失败 |
| 42 | + </view> |
| 43 | + </template> |
| 44 | + <template #loading> |
| 45 | + <view class="loading-wrap"> |
| 46 | + <wd-loading/> |
| 47 | + </view> |
| 48 | + </template> |
| 49 | + </wd-img> |
| 50 | +</template> |
| 51 | +
|
| 52 | +<style> |
| 53 | +.error-wrap { |
| 54 | + width: 100%; |
| 55 | + height: 100%; |
| 56 | + background-color: red; |
| 57 | + color: white; |
| 58 | + line-height: 100px; |
| 59 | + text-align: center; |
| 60 | +} |
| 61 | +
|
| 62 | +.loading-wrap { |
| 63 | + width: 100%; |
| 64 | + height: 100%; |
| 65 | + display: flex; |
| 66 | + justify-content: center; |
| 67 | + align-items: center; |
| 68 | +} |
| 69 | +</style> |
| 70 | +``` |
| 71 | + |
33 | 72 | ## 填充模式 |
34 | 73 |
|
35 | 74 | 通过 `mode` 属性可以设置图片填充模式,可选值见下方表格。 |
@@ -73,27 +112,34 @@ mode为小程序原生属性,参考[微信小程序image官方文档](https:// |
73 | 112 |
|
74 | 113 | ## Attributes |
75 | 114 |
|
76 | | -| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | |
77 | | -|-----|------|-----|-------|-------|---------| |
78 | | -| src | 图片链接 | string | - | - | - | |
79 | | -| width | 宽度,默认单位为px | number / string | - | - | - | |
80 | | -| height | 高度,默认单位为px | number / string | - | - | - | |
81 | | -| mode | 填充模式 | ImageMode | 'top left' / 'top right' / 'bottom left' / 'bottom right' / 'right' / 'left' / 'center' / 'bottom' / 'top' / 'heightFix' / 'widthFix' / 'aspectFill' / 'aspectFit' / 'scaleToFill' | 'scaleToFill' | - | |
82 | | -| round | 是否显示为圆形 | boolean | - | false | - | |
83 | | -| radius | 圆角大小,默认单位为px | number / string | - | - | - | |
84 | | -| enable-preview | 是否支持点击预览 | boolean | - | false | 1.2.11 | |
| 115 | +| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | |
| 116 | +| -------------- | ---------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -------- | |
| 117 | +| src | 图片链接 | string | - | - | - | |
| 118 | +| width | 宽度,默认单位为px | number / string | - | - | - | |
| 119 | +| height | 高度,默认单位为px | number / string | - | - | - | |
| 120 | +| mode | 填充模式 | ImageMode | 'top left' / 'top right' / 'bottom left' / 'bottom right' / 'right' / 'left' / 'center' / 'bottom' / 'top' / 'heightFix' / 'widthFix' / 'aspectFill' / 'aspectFit' / 'scaleToFill' | 'scaleToFill' | - | |
| 121 | +| round | 是否显示为圆形 | boolean | - | false | - | |
| 122 | +| radius | 圆角大小,默认单位为px | number / string | - | - | - | |
| 123 | +| enable-preview | 是否支持点击预览 | boolean | - | false | 1.2.11 | |
85 | 124 |
|
86 | 125 | ## Events |
87 | 126 |
|
88 | | -| 事件名称 | 说明 | 参数 | 最低版本 | |
89 | | -|---------|-----|-----|---------| |
90 | | -| click | 点击事件 | - | - | |
91 | | -| load | 当图片载入完毕时触发 | ` {height, width}` | - | |
92 | | -| error | 当错误发生时触发 | `{errMsg}` | - | |
| 127 | +| 事件名称 | 说明 | 参数 | 最低版本 | |
| 128 | +| -------- | -------------------- | ----------------- | -------- | |
| 129 | +| click | 点击事件 | - | - | |
| 130 | +| load | 当图片载入完毕时触发 | `{height, width}` | - | |
| 131 | +| error | 当错误发生时触发 | `{errMsg}` | - | |
| 132 | + |
| 133 | +## Slots |
| 134 | + |
| 135 | +| 名称 | 说明 | 最低版本 | |
| 136 | +| ------- | ------------------ | ---------------- | |
| 137 | +| loading | 图片加载时展示 | $LOWEST_VERSION$ | |
| 138 | +| error | 图片加载失败后展示 | $LOWEST_VERSION$ | |
93 | 139 |
|
94 | 140 | ## 外部样式类 |
95 | 141 |
|
96 | | -| 类名 | 说明 | 最低版本 | |
97 | | -|-----|------|--------| |
98 | | -| custom-class | 根节点样式 | - | |
99 | | -| custom-image| image 外部自定义样式 | - | |
| 142 | +| 类名 | 说明 | 最低版本 | |
| 143 | +| ------------ | -------------------- | -------- | |
| 144 | +| custom-class | 根节点样式 | - | |
| 145 | +| custom-image | image 外部自定义样式 | - | |
0 commit comments