Astro に統合する

インストールと基本的な使い方を最初に読みます。以下の例では、UniverのページでAstroドキュメントをマウントし、明示的な高さを持つコンテナ内にあります。

ブラウザで実行するように、エディタをプレーン<script>タグから初期化します。 この初期化をastro:page-loadで実行し、ClientRouterが使用したときにastro:before-swapの前にエディタをディスポースします。 エディタはAstroのフロントマッターからインポートしてください。 イベントの詳細はAstroのナビゲーションイベントで文書化されます。

統合手順

  1. mount() / astro:page-load で Univer を初期化します。
  2. astro:before-swap でそれの処分。

プリセット設定

UniverDocsCorePreset

  • container
    string | HTMLElement既定値: 'app'
    エディターのマウント先となる DOM 要素、またはその ID。

事例紹介

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>

このガイドはいかがですか?

© 2026 DreamNum Co., Ltd.