在 Vue 中整合

請先閱讀安裝和基本使用。下面的 Vue 元件將 Univer Pdfs 掛載到容器中,容器高度需要顯式指定。

整合步驟

  1. 在 onMounted 中建立 Univer 例項。
  2. 在 onBeforeUnmount 中銷燬該例項。

外掛設定

UniverUIPlugin

  • container
    string | HTMLElement
    掛載目標 DOM 元素或元素 ID。

UniverLicensePlugin

  • license
    string
    用戶端授權檔的內容。

範例程式碼

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>

你覺得這篇文檔如何?

© 2026 DreamNum Co., Ltd.