当前位置:   article > 正文

vue3使用vue-pdf-embed预览文件流格式的pdf文件

vue-pdf-embed

效果图:

 

安装npm install vue3-pdfjs、npm install vue-pdf-embed

source格式传递字符串

'data:application/pdf;base64,' + 接口获取的文件流;

  1. <template>
  2. <el-button @click="close">{{$t('common.navbar.back')}}</el-button>
  3. <template v-if="sShow">
  4. <vue-pdf-embed :source="source" />
  5. </template>
  6. </template>
  7. <script setup>
  8. import { pervDoc } from '@/api/doc/doc'
  9. import { ref } from '@vue/reactivity';
  10. import VuePdfEmbed from "vue-pdf-embed";
  11. const emit = defineEmits(["close"]);
  12. function close () {
  13. emit("close");
  14. }
  15. const props = defineProps({
  16. docId: {
  17. type: Number
  18. }
  19. })
  20. const source = ref('');
  21. const sShow = ref(false)
  22. function getSource () {
  23. pervDoc(props.docId).then(res => {
  24. if (res.status == "success") {
  25. source.value = 'data:application/pdf;base64,' + res.data.base64File;
  26. sShow.value = true;
  27. }
  28. }).catch(function (err) {
  29. console.log(err);
  30. })
  31. }
  32. onMounted(() => {
  33. getSource();
  34. })
  35. </script>
  36. <style>
  37. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/880373
推荐阅读
相关标签
  

闽ICP备14008679号