在 Vue 中集成

本页从安装和基本使用开始。下面的单文件组件将 Univer Bases 挂载到一个高度固定的容器中。

集成步骤

  1. 在 onMounted 中初始化 Univer。
  2. 在 onBeforeUnmount 中销毁 Univer。

插件配置

UniverUIPlugin

  • container
    string | HTMLElement
    编辑器挂载目标的 DOM 元素或其 ID。

UniverLicensePlugin

  • license
    string
    客户端许可证文件的内容。

示例代码

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 BasesUIzhCN from '@univerjs-pro/bases-ui/locale/zh-CN'import BaseszhCN from '@univerjs-pro/bases/locale/zh-CN'import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'import { UniverLicensePlugin } from '@univerjs-pro/license'import { LocaleType, mergeLocales, Univer, UniverInstanceType } from '@univerjs/core'import DesignzhCN from '@univerjs/design/locale/zh-CN'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'import { UniverUIPlugin } from '@univerjs/ui'import UIzhCN from '@univerjs/ui/locale/zh-CN'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_CN,    locales: {      [LocaleType.ZH_CN]: mergeLocales(        DesignzhCN,        UIzhCN,        BaseszhCN,        BasesUIzhCN,      ),    },  })  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.