是需要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>