0
点赞
收藏
分享

微信扫一扫

vue3实现在element Dialog 对话框中预览pdf文件

TiaNa_na 2023-10-20 阅读 72

下面直接看具体应用吧,我是把它单独拎出页面写的,所以直接在需要用到的组件里引入,想要传什么值自行添加即可

<template>
  <!-- 弹出框 -->
  <el-dialog
    title="pdf预览.pdf"
    v-model="openPdf"
    @close="onClose"
    :close-on-click-modal="false"
    width="1050px"
  >
  <!-- 预览pdf文件 -->
    <embed
      src="https://www.latex-project.org/help/documentation/usrguide.pdf"
      type="application/pdf"
      width="1010px"
      height="600px"
    />
  </el-dialog>
</template>

<script setup name="showPdf">
import { ref, reactive, computed, watch, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
// 是否打开弹窗
const openPdf = ref(false);

const props = defineProps({
  openPdf:{
    type:Boolean
  },
  uuid:{
    type:String
  },
  title:{
    type:String
  }
})
// 关闭弹窗
const onClose =()=>{
  openPdf.value = false;
}
</script>

<style lang="scss" scoped></style>


<template>
     <button @click="openDetail">打开弹窗</button>
     <!-- 弹窗 -->
     <showPdf v-model="openPdf" :uuid="uuid"></showPdf>
  </div>
</template>

<script setup>
import { ref} from "vue";
import showPdf from "@/views/showPdf.vue" // 引入前面写好的弹窗组件

const uuid = ref(null);
const openPdf = ref(false);

/**打开pdf弹窗 */
const openDetail=()=> {
  openPdf.value = true;
};
</script>

<style lang="scss" scoped></style>

效果图:
在这里插入图片描述

举报

相关推荐

0 条评论