vue3 H5项目中实现PDF预览

是需要npm i vue-pdf-embed 安装这个插件的,可兼容ios/Android,下面是本人的使用实例

javascript 复制代码
<template>
    <div class="conten_box">
        <vue-pdf-embed v-if="pdfSource.url" :source="pdfSource" />
    </div>
</template>
<script setup>
import { onMounted, ref, reactive } from 'vue'
import { ylhtPdf } from "@/api/ht/index";
import VuePdfEmbed from "vue-pdf-embed";

const pdfSource = reactive({
    url: "",
    cMapUrl: "https://cdn.jsdelivr.net/npm/pdfjs-dist@2.16.105/cmaps/",
    cMapPacked: true,
});

// 获取pdf需要的url
const getInvitation = () => {
    ylhtPdf().then(({ data: { code, data, message } }) => {
        pdfSource.url = data.contract;
    })
    .catch(() => {});
}

onMounted(() => {
    getInvitation()
})

</script>
相关推荐
Erishen10 分钟前
🚀 重新定义前端组件安装体验:shadcn + Bun 的极致开发效率
前端
冬奇Lab10 分钟前
Vercel部署全攻略:从GitHub到上线,10分钟让你的前端项目免费拥有自己的域名
前端·后端·node.js
浮尘202510 分钟前
PC端pdf软件测评
pdf·软件评测
牛马11113 分钟前
Flutter Web性能优化标签解析
前端·flutter·性能优化
Bigger13 分钟前
Tauri (25)——消除搜索列表默认选中的 UI 闪动
前端·react.js·weui
李少兄25 分钟前
简单讲讲 SVG:前端开发中的矢量图形
前端·svg
SEO-狼术25 分钟前
PDF Content Through the Viewer
pdf
前端小万26 分钟前
告别 CJS 库加载兼容坑
前端·前端工程化
恋猫de小郭26 分钟前
Flutter 3.38.1 之后,因为某些框架低级错误导致提交 Store 被拒
android·前端·flutter
JarvanMo30 分钟前
Flutter 需要 Hooks 吗?
前端