在 Vue 中整合
請先閱讀安裝和基本使用。下面的範例在 Vue 元件中掛載 Univer Slides,併為容器設定明確的高度。
整合步驟
- 在
onMounted中初始化 Univer。 - 在
onBeforeUnmount中銷燬例項。
外掛設定
UniverUIPlugin
containerstring | HTMLElement編輯器掛載的 DOM 元素或元素 ID。
UniverLicensePlugin
licensestring用戶端授權檔的內容。
範例程式碼
Vue
<script setup lang="ts">import { onBeforeUnmount, onMounted, ref } from 'vue'import { UniverLicensePlugin } from '@univerjs-pro/license'import { UniverSlidesPlugin } from '@univerjs-pro/slides'import { UniverSlidesUIPlugin } from '@univerjs-pro/slides-ui'import SlidesUIzhTW from '@univerjs-pro/slides-ui/locale/zh-TW'import SlideszhTW from '@univerjs-pro/slides/locale/zh-TW'import { LocaleType, mergeLocales, Univer, UniverInstanceType } from '@univerjs/core'import DesignzhTW from '@univerjs/design/locale/zh-TW'import { UniverDocsPlugin } from '@univerjs/docs'import { UniverDocsUIPlugin } from '@univerjs/docs-ui'import DocsUIzhTW from '@univerjs/docs-ui/locale/zh-TW'import { UniverDrawingPlugin } from '@univerjs/drawing'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'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/docs-ui/lib/index.css'import '@univerjs-pro/slides-ui/lib/index.css'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, DocsUIzhTW, SlideszhTW, SlidesUIzhTW, ), }, }) univer.registerPlugin(UniverLicensePlugin, { license: 'your license.txt', }) univer.registerPlugin(UniverRenderEnginePlugin) univer.registerPlugin(UniverUIPlugin, { container, }) univer.registerPlugin(UniverDocsPlugin) univer.registerPlugin(UniverDocsUIPlugin) univer.registerPlugin(UniverDrawingPlugin) univer.registerPlugin(UniverSlidesPlugin) univer.registerPlugin(UniverSlidesUIPlugin) univer.createUnit(UniverInstanceType.UNIVER_SLIDE, {}) univerInstance = univer})onBeforeUnmount(() => univerInstance?.dispose())</script><template> <div ref="containerRef" style="height: 600px" /></template>你覺得這篇文檔如何?