在 Vue 中整合

請先閱讀安裝與基本使用。以下範例透過 Vue 將 Univer Bases 掛載到具有明確高度的容器中。

整合步驟

  1. 在 onMounted 中初始化 Univer
  2. 在 onBeforeUnmount 中銷毀 Univer

範例程式碼

Vue
<script setup lang="ts">import { onBeforeUnmount, onMounted, ref } from 'vue'import { UniverBasesPlugin } from '@univerjs-pro/bases'import { UniverBasesUIPlugin } from '@univerjs-pro/bases-ui'import BasesUIzhTW from '@univerjs-pro/bases-ui/locale/zh-TW'import BaseszhTW from '@univerjs-pro/bases/locale/zh-TW'import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'import { UniverLicensePlugin } from '@univerjs-pro/license'import { LocaleType, mergeLocales, Univer, UniverInstanceType } from '@univerjs/core'import DesignzhTW from '@univerjs/design/locale/zh-TW'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-pro/bases-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,        BaseszhTW,        BasesUIzhTW,      ),    },  })  univer.registerPlugin(UniverLicensePlugin, {    license: 'your license.txt',  })  univer.registerPlugin(UniverRenderEnginePlugin)  univer.registerPlugin(UniverUIPlugin, { container })  univer.registerPlugin(UniverProFormulaEnginePlugin)  univer.registerPlugin(UniverBasesPlugin)  univer.registerPlugin(UniverBasesUIPlugin)  univer.createUnit(UniverInstanceType.UNIVER_BASE, {})  univerInstance = univer})onBeforeUnmount(() => univerInstance?.dispose())</script><template>  <div ref="containerRef" style="height: 600px" /></template>

你覺得這篇文檔如何?

© 2026 DreamNum Co., Ltd.