Blame view

src/views/demo/feat/img-preview/index.vue 1.18 KB
陈文彬 authored
1
<template>
2
  <PageWrapper title="图片预览示例">
vben authored
3
    <ImagePreview :imageList="imgList" />
4
    <a-button @click="openImg" type="primary">无预览图</a-button>
5
  </PageWrapper>
陈文彬 authored
6
7
8
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
9
  import { createImgPreview, ImagePreview } from '/@/components/Preview/index';
10
  import { PageWrapper } from '/@/components/Page';
11
  // import { PreviewActions } from '/@/components/Preview/src/typing';
12
陈文彬 authored
13
14
15
16
17
18
  const imgList: string[] = [
    'https://picsum.photos/id/66/346/216',
    'https://picsum.photos/id/67/346/216',
    'https://picsum.photos/id/68/346/216',
  ];
  export default defineComponent({
19
    components: { PageWrapper, ImagePreview },
陈文彬 authored
20
    setup() {
21
      function openImg() {
22
23
24
25
26
        const onImgLoad = ({ index, url, dom }) => {
          console.log(`第${index + 1}张图片已加载,URL为:${url}`, dom);
        };
        // 可以使用createImgPreview返回的 PreviewActions 来控制预览逻辑,实现类似幻灯片、自动旋转之类的骚操作
        createImgPreview({ imageList: imgList, defaultWidth: 700, rememberState: true, onImgLoad });
27
28
      }
      return { imgList, openImg };
陈文彬 authored
29
30
31
    },
  });
</script>