0
点赞
收藏
分享

微信扫一扫

Spring Cloud微服务:构建弹性、可扩展的分布式系统

茗越 2024-11-08 阅读 6

文章目录

1.使用场景

2. 使用方式

1. npm 包下载,点击查看

2. 官网下载

1. 放到public文件夹下面

在这里插入图片描述

2. 官网下载地址点我,进入官网

3. 代码演示

<template>
    <div class="pdf-preview">
        <el-row>
            <el-col :span="24">
                <el-button @click="handleChooseLocalFile" type="primary">选择本地文件</el-button>
            </el-col>
        </el-row>
        <iframe class="pdf-iframe" :src="previewURL" width="100%" height="800px" v-if="previewURL"></iframe>
    </div>
</template>
<script>
export default {
    name: "pdfPreview",
    data() {
        return {
            // public 下面的路径
            pdfJsViewer: "/pdfjs-4.8.69/web/viewer.html",
            fileUrl: "/pdfjs-4.8.69/web/compressed.tracemonkey-pldi-09.pdf",
        };
    },

    computed: {
        previewURL() {
            return this.fileUrl ? `${this.pdfJsViewer}?file=${encodeURIComponent(this.fileUrl)}` : "";
        },
    },
    methods: {
        handleChooseLocalFile() {
            let input = document.createElement("input");
            input.type = "file";
            input.accept = ".pdf";
            input.multiple = false;
            input.onchange = (e) => {
                let file = e.target.files[0];
                if (file) {
                    this.fileUrl = URL.createObjectURL(file);
                }
            };
            input.click();
            input.remove();
        },
    },
};
</script>

<style scoped lang="scss">
.inner-tool {
    display: flex;
    flex-direction: column;
}
.pdf-preview {
    flex: 1;
}
.pdf-iframe {
    margin-top: 20px;
    height: calc(100vh - 150px);
}
</style>

4. 图片预览

在这里插入图片描述

5. 如果遇到跨域或者application/octet-stream等问题

举报

相关推荐

0 条评论