Astro に統合する

このページは インストールと基本的な使い方 から始まります。例は、Astro ページ内の Univer Bases を、明示的な高さを持つコンテナ内でマウントします。

<script>は、ブラウザでエディタを直接初期化します。最初のロードとastro:page-loadで初期化を実行し、ClientRouterが使用している場合、astro:before-swapの前にインスタンスをディスポースします。エディタはAstroフロントマッタからインポートしてください。 Astroナビゲーションイベントを参照してください。

統合手順

  1. mount() / astro:page-load で Univer を初期化します。
  2. astro:before-swap のインスタンスをディスポースします。

プラグイン設定

UniverUIPlugin

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

UniverLicensePlugin

  • license
    string
    クライアント用ライセンスファイルの内容。

事例紹介

Astro
<div id="univer-bases" style="height: 600px"></div><script>  import { UniverBasesPlugin } from '@univerjs-pro/bases'  import { UniverBasesUIPlugin } from '@univerjs-pro/bases-ui'  import BasesUIjaJP from '@univerjs-pro/bases-ui/locale/ja-JP'  import BasesjaJP from '@univerjs-pro/bases/locale/ja-JP'  import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'  import { UniverLicensePlugin } from '@univerjs-pro/license'  import { LocaleType, mergeLocales, Univer, UniverInstanceType } from '@univerjs/core'  import DesignjaJP from '@univerjs/design/locale/ja-JP'  import { UniverRenderEnginePlugin } from '@univerjs/engine-render'  import { UniverUIPlugin } from '@univerjs/ui'  import UIjaJP from '@univerjs/ui/locale/ja-JP'  import '@univerjs/design/lib/index.css'  import '@univerjs/ui/lib/index.css'  import '@univerjs-pro/bases-ui/lib/index.css'  let univerInstance: Univer | undefined  function mount() {    const container = document.getElementById('univer-bases')    if (!container || univerInstance) return    const univer = new Univer({      locale: LocaleType.JA_JP,      locales: {        [LocaleType.JA_JP]: mergeLocales(          DesignjaJP,          UIjaJP,          BasesjaJP,          BasesUIjaJP,        ),      },    })    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  }  function dispose() {    univerInstance?.dispose()    univerInstance = undefined  }  mount()  document.addEventListener('astro:page-load', mount)  document.addEventListener('astro:before-swap', dispose)</script>

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

© 2026 DreamNum Co., Ltd.