在 Web Component 中整合
如需在編輯器中使用 Web Component 作為自定義元件,請參閱自定義元件。
Univer 可以執行在 Web Component 中。
預設設定
UniverSheetsCorePreset
containerstring | HTMLElement預設值:'app'編輯器掛載的元素,或該元素的 DOM ID。
範例程式碼
TypeScript
import type { Univer } from '@univerjs/presets'import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core'import UniverPresetSheetsCoreZhTW from '@univerjs/preset-sheets-core/locales/zh-TW'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-sheets-core/lib/index.css'class UniverEditorElement extends HTMLElement { private univer?: Univer connectedCallback() { if (this.univer) return const container = this const { univer, univerAPI } = createUniver({ locale: LocaleType.ZH_TW, locales: { [LocaleType.ZH_TW]: mergeLocales( UniverPresetSheetsCoreZhTW, ), }, presets: [ UniverSheetsCorePreset({ container, }), ], }) univerAPI.createWorkbook({}) this.univer = univer } disconnectedCallback() { this.univer?.dispose() this.univer = undefined }}customElements.define('univer-sheets-editor', UniverEditorElement)HTML
<univer-sheets-editor style="display: block; height: 600px"></univer-sheets-editor>你覺得這篇文檔如何?