diff --git a/src/image/README.zh-CN.md b/src/image/README.zh-CN.md index 12bb6e37e..36cd3cc5a 100644 --- a/src/image/README.zh-CN.md +++ b/src/image/README.zh-CN.md @@ -120,7 +120,7 @@ app.use(Lazyload); | cover | 保持宽高缩放图片,使图片的短边能完全显示出来,裁剪长边 | | fill | 拉伸图片,使图片填满元素 | | none | 保持图片原有尺寸 | -| scale-down | 取`none`或`contain`中较小的一个 | +| scale-down | 取 `none` 或 `contain` 中较小的一个 | ### Events diff --git a/src/image/index.js b/src/image/index.tsx similarity index 89% rename from src/image/index.js rename to src/image/index.tsx index aade22759..416a036e0 100644 --- a/src/image/index.js +++ b/src/image/index.tsx @@ -1,14 +1,16 @@ -import { ref, watch, computed } from 'vue'; +import { ref, watch, computed, PropType } from 'vue'; import { createNamespace, isDef, addUnit } from '../utils'; import Icon from '../icon'; const [createComponent, bem] = createNamespace('image'); +export type ImageFit = 'contain' | 'cover' | 'fill' | 'none' | 'scale-down'; + export default createComponent({ props: { src: String, - fit: String, alt: String, + fit: String as PropType, round: Boolean, width: [Number, String], height: [Number, String], @@ -40,7 +42,7 @@ export default createComponent({ const imageRef = ref(); const style = computed(() => { - const style = {}; + const style: Record = {}; if (isDef(props.width)) { style.width = addUnit(props.width); @@ -66,12 +68,12 @@ export default createComponent({ } ); - const onLoad = (event) => { + const onLoad = (event: Event) => { loading.value = false; emit('load', event); }; - const onError = (event) => { + const onError = (event: Event) => { error.value = true; loading.value = false; emit('error', event); @@ -103,7 +105,7 @@ export default createComponent({ }; const renderImage = () => { - if (props.error || !props.src) { + if (error.value || !props.src) { return; } @@ -116,7 +118,7 @@ export default createComponent({ }; if (props.lazyLoad) { - return ; + return ; } return (