Browse Source

fix(imagePreview): replace the type for images (#1543)

hydraZty 3 years ago
parent
commit
c2c570b5f6

+ 1 - 1
src/packages/__VUE/imagepreview/doc.md

@@ -303,7 +303,7 @@ app.use(ImagePreview);
 |----- | ----- | ----- | ----- 
 | show | 是否展示预览图片 | Boolean | false
 | videos | 预览的视频数组(视频自动放到图片之前、taro场景暂不支持) | Array<`Object`> | []
-| images | 预览图片数组 | Array<`String`> | []
+| images | 预览图片数组 | { src: String }[] | []
 | autoplay | 自动轮播时长,0表示不会自动轮播 | Number、String  | 3000  |
 | init-no | 初始页码 | Number | 1
 | pagination-visible | 分页指示器是否展示    | Boolean | false |

+ 7 - 6
src/packages/__VUE/imagepreview/index.ts

@@ -1,12 +1,13 @@
 import ImagePreview from './index.vue';
 import { render, createVNode, h } from 'vue';
+import { ImageInterface } from './types'
 export class ImagePreviewOptions {
-  show?: Boolean = false;
-  images?: Array<string> = [];
-  initNo?: Number = 1;
-  paginationVisible?: Boolean = false;
-  paginationColor?: string = '';
-  teleport?: String | HTMLElement = 'body';
+  show: Boolean = false;
+  images: ImageInterface[] = [];
+  initNo: Number = 1;
+  paginationVisible: Boolean = false;
+  paginationColor: string = '';
+  teleport: String | HTMLElement = 'body';
 
   // function
   onClose?: Function = () => {};

+ 3 - 1
src/packages/__VUE/imagepreview/index.vue

@@ -55,6 +55,7 @@
 </template>
 <script lang="ts">
 import { toRefs, reactive, watch, onMounted, ref, computed } from 'vue';
+import type { PropType } from 'vue'
 import { createComponent } from '@/packages/utils/create';
 import Popup from '../popup/index.vue';
 import Video from '../video/index.vue';
@@ -63,6 +64,7 @@ import SwiperItem from '../swiperitem/index.vue';
 import Icon from '../icon/index.vue';
 import { isPromise } from '@/packages/utils/util.ts';
 import ImagePreviewItem from './imagePreviewItem.vue';
+import { ImageInterface } from './types'
 const { componentName, create } = createComponent('imagepreview');
 
 export default create({
@@ -72,7 +74,7 @@ export default create({
       default: false
     },
     images: {
-      type: Array,
+      type: Array as PropType<ImageInterface[]>,
       default: () => []
     },
     videos: {

+ 3 - 0
src/packages/__VUE/imagepreview/types.ts

@@ -0,0 +1,3 @@
+export interface ImageInterface {
+  src: string;
+}