inleft
2022-08-23 93768186ca58acd0fc0b6963d0e017979c087631
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<template>
    <div>
        <button type="button" class="button" @click="previewURL">URL Array</button>
        <button type="button" class="button" @click="previewImgObject">Img-Object Array</button>
    </div>
</template>
<script>
    import 'viewerjs/dist/viewer.css'
    import {
        api as viewerApi
    } from "v-viewer"
    export default {
        data() {
            return {
                sourceImageURLs: [
                    'https://picsum.photos/200/200?random=1',
                    'https://picsum.photos/200/200?random=2',
                ],
                sourceImageObjects: [{
                        'src': 'https://picsum.photos/200/200?random=3',
                        'data-source': 'https://picsum.photos/800/800?random=3'
                    },
                    {
                        'src': 'https://picsum.photos/200/200?random=4',
                        'data-source': 'https://picsum.photos/800/800?random=4'
                    }
                ]
            }
        },
        methods: {
            previewURL() {
                // 如果使用`app.use`进行全局安装, 你就可以像这样直接调用`this.$viewerApi`
                const $viewer = this.$viewerApi({
                    images: this.sourceImageURLs
                })
            },
            previewImgObject() {
                // 或者你可以单独引入api然后执行它
                const $viewer = viewerApi({
                    options: {
                        inline:true,
                        toolbar: true,
                        url: 'data-source',
                        initialViewIndex: 1
                    },
                    images: this.sourceImageObjects
                })
            }
        }
    }
</script>