Astro に統合する
まずインストールと基本的な使い方を参照してください。以下は Astro を使い、高さを明示したコンテナーに Univer Docs をマウントする例です。
通常の <script> でブラウザー上にエディターを直接初期化します。初回読み込み時に初期化し、ClientRouter 使用時は astro:page-load で再マウント、astro:before-swap で破棄します。Astro frontmatter ではエディターをインポートしないでください。Astro のナビゲーションイベントを参照してください。
統合手順
mount()/astro:page-loadで Univer を初期化します。astro:before-swapで Univer を破棄します。
サンプルコード
Astro
<div id="univer-docs" style="height: 600px"></div><script> import type { Univer } from '@univerjs/presets' import { UniverDocsCorePreset } from '@univerjs/preset-docs-core' import UniverPresetDocsCorejaJP from '@univerjs/preset-docs-core/locales/ja-JP' import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets' import '@univerjs/preset-docs-core/lib/index.css' let univerInstance: Univer | undefined function mount() { const container = document.getElementById('univer-docs') if (!container || univerInstance) return const { univer, univerAPI } = createUniver({ locale: LocaleType.JA_JP, locales: { [LocaleType.JA_JP]: mergeLocales(UniverPresetDocsCorejaJP) }, presets: [UniverDocsCorePreset({ container })], }) univerAPI.createDocument({}) univerInstance = univer } function dispose() { univerInstance?.dispose() univerInstance = undefined } mount() document.addEventListener('astro:page-load', mount) document.addEventListener('astro:before-swap', dispose)</script>このガイドはいかがですか?