vite使用vue-pdf
时间: 2024-03-26 13:31:24 浏览: 283
根据提供的引用内容,以下是使用Vite和Vue-PDF组件的示例代码:
1. 在项目中安装Vue-PDF组件:
```shell
npm install vue-pdf
```
2. 在Vite项目中引入Vue-PDF组件:
```javascript
import { createApp } from 'vue';
import PdfView from 'vue-pdf';
const app = createApp();
app.component('PdfView', PdfView);
app.mount('#app');
```
3. 创建PdfView组件并使用:
```vue
<template>
<div class="pdfView">
<PdfView :showPdf="showPdf" :pdfUrl="pdfUrl" />
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
const showPdf = ref(false);
const pdfUrl = ref("");
// 调用获取文件流接口
const handleGetPdf = async () => {
try {
const res = await getReportDoc({ reportDocId: state.reportDocId });
pdfUrl.value = window.URL.createObjectURL(res) + "#toolbar=1";
} catch (error) {
console.log(error);
}
};
</script>
<style scoped lang="less">
.pdfView {
width: 100%;
height: 100%;
}
</style>
```
请注意,上述代码中的`getReportDoc`函数和`state.reportDocId`变量需要根据实际情况进行替换。此外,确保在项目中正确引入Vue和Vue-PDF组件。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)