在 Vue 中整合
請先閱讀安裝與基本使用。以下範例透過 Vue 將 Univer Pdfs 掛載到具有明確高度的容器中。
整合步驟
- 在
onMounted中初始化 Univer - 在
onBeforeUnmount中銷毀 Univer
範例程式碼
Vue
<script setup lang="ts">import { onBeforeUnmount, onMounted, ref } from 'vue'import { UniverLicensePlugin } from '@univerjs-pro/license'import { UniverPdfsPlugin } from '@univerjs-pro/pdfs'import { UniverPdfsUIPlugin } from '@univerjs-pro/pdfs-ui'import PdfsUIzhTW from '@univerjs-pro/pdfs-ui/locale/zh-TW'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { FUniver } from '@univerjs/core/facade'import DesignzhTW from '@univerjs/design/locale/zh-TW'import { UniverUIPlugin } from '@univerjs/ui'import UIzhTW from '@univerjs/ui/locale/zh-TW'import '@univerjs/design/lib/index.css'import '@univerjs/ui/lib/index.css'import '@univerjs-pro/pdfs-ui/lib/index.css'import '@univerjs-pro/pdfs/facade'const containerRef = ref<HTMLDivElement | null>(null)let univerInstance: Univer | undefinedonMounted(() => { const container = containerRef.value if (!container) return const univer = new Univer({ locale: LocaleType.ZH_TW, locales: { [LocaleType.ZH_TW]: mergeLocales( DesignzhTW, UIzhTW, PdfsUIzhTW, ), }, }) univer.registerPlugin(UniverLicensePlugin, { license: 'your license.txt', }) univer.registerPlugin(UniverUIPlugin, { container }) univer.registerPlugin(UniverPdfsPlugin) univer.registerPlugin(UniverPdfsUIPlugin) const univerAPI = FUniver.newAPI(univer) univerAPI.createPdf({ name: 'Untitled PDF' }) univerInstance = univer})onBeforeUnmount(() => univerInstance?.dispose())</script><template> <div ref="containerRef" style="height: 600px" /></template>你覺得這篇文檔如何?