Skip to content

Commit b0b8e3e

Browse files
committed
feat(image): support fallback
1 parent 7d3a73a commit b0b8e3e

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

src/image/image.en-US.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ name | type | default | description | required
88
-- | -- | -- | -- | --
99
alt | String | - | \- | N
1010
error | String / Slot / Function | - | Typescript:`string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N
11+
fallback | String | - | display `fallback` image on `src` loading failed. you can also use `error` to define more complex error content | N
1112
fit | String | fill | options: contain/cover/fill/none/scale-down | N
1213
lazy | Boolean | false | \- | N
1314
loading | String / Slot / Function | - | Typescript:`string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N

src/image/image.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-- | -- | -- | -- | --
99
alt | String | - | 图片描述 | N
1010
error | String / Slot / Function | - | 自定义图片加载失败状态下的显示内容。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N
11+
fallback | String | - | 图片加载失败时,显示当前链接设置的图片地址。如果要使用组件图标或完全自定义加载失败时显示的内容,请更为使用 `error` | N
1112
fit | String | fill | 图片填充模式。可选项:contain/cover/fill/none/scale-down | N
1213
lazy | Boolean | false | 是否开启图片懒加载 | N
1314
loading | String / Slot / Function | - | 自定义加载中状态的图片内容,如:“加载中”。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N

src/image/image.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export default defineComponent({
6666
props.onError?.({ e });
6767
isLoading.value = false;
6868
isError.value = true;
69+
if (props.fallback) {
70+
realSrc.value = props.fallback;
71+
isError.value = false;
72+
}
6973
};
7074

7175
const maskContent = computed(() => {

src/image/props.ts

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export default {
1717
error: {
1818
type: [String, Function] as PropType<TdImageProps['error']>,
1919
},
20+
/** 图片加载失败时,显示当前链接设置的图片地址。如果要使用组件图标或完全自定义加载失败时显示的内容,请更为使用 `error` */
21+
fallback: {
22+
type: String,
23+
default: '',
24+
},
2025
/** 图片填充模式 */
2126
fit: {
2227
type: String as PropType<TdImageProps['fit']>,

src/image/type.ts

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export interface TdImageProps {
1616
* 自定义图片加载失败状态下的显示内容
1717
*/
1818
error?: string | TNode;
19+
/**
20+
* 图片加载失败时,显示当前链接设置的图片地址。如果要使用组件图标或完全自定义加载失败时显示的内容,请更为使用 `error`
21+
* @default ''
22+
*/
23+
fallback?: string;
1924
/**
2025
* 图片填充模式
2126
* @default fill

0 commit comments

Comments
 (0)