快速入门
安装
通过 ESM npm 包或 UMD CDN 安装 SVeditor,并引入样式。
安装
SVeditor 只能在浏览器中运行。你需要 SDK 包或脚本,以及 @wztlink1013/sveditor/style.css。缺少样式时,工具栏和菜单会显示异常。
推荐:ESM 包
适用于 React、Next.js、Vite 及任何带 bundler 的应用:
| 主题 | 指南 |
|---|---|
| 安装、导入、SSR | ESM 集成 |
| React / Next.js 模式 | React / Next.js |
| 首次挂载 | 快速开始 |
pnpm add @wztlink1013/sveditor@0.2.16"use client";
import { SVeditor } from "@wztlink1013/sveditor";
import "@wztlink1013/sveditor/style.css";若许可证使用私有 scoped registry,请按 ESM 集成 配置 .npmrc。
仅当服务端实现协作 API 时,才需安装 @wztlink1013/sveditor-collab-schema。
备选:CDN(UMD)
适用于无 bundler 的传统页面。UMD 包内已包含 React。
生产环境请锁定版本(下列为 0.2.16,升级时请替换):
<link
rel="stylesheet"
href="https://static.editor.showverge.com/sdk/sveditor/0.2.16/sv-editor-sdk.css"
/>
<script src="https://static.editor.showverge.com/sdk/sveditor/0.2.16/sv-editor-sdk.umd.js"></script>
<script>
const editor = window.SVeditor.create({
el: "#editor",
content: "<p>Hello world</p>",
});
window.addEventListener("beforeunload", () => editor.destroy());
</script>完整示例见 CDN 集成。
浏览器兼容性
| 浏览器 | 最低版本 |
|---|---|
| Chrome | 90+ |
| Firefox | 88+ |
| Safari | 14+ |
| Edge | 90+ |
不支持 Internet Explorer。