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 UniverPresetDocsCorekoKR from '@univerjs/preset-docs-core/locales/ko-KR' 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.KO_KR, locales: { [LocaleType.KO_KR]: mergeLocales(UniverPresetDocsCorekoKR) }, 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>이 가이드는 어떠셨나요?