# - 使用React组件集成ONLYOFFICE

# 安装 ONLYOFFICE 文档 React 组件

在您的项目中从 npm 安装 ONLYOFFICE 文档 React 组件。运行命令:

npm install --save @onlyoffice/document-editor-react
1

或者

yarn add @onlyoffice/document-editor-react
1

# 使用 ONLYOFFICE 文档 React 组件

下面是组件使用示例:

...
import { DocumentEditor } from "@onlyoffice/document-editor-react";
...
...
var onDocumentReady = function (event) {
    console.log("Document is loaded");
};
...
...
<DocumentEditor
  id="docxEditor"
  documentServerUrl="http://documentserver/"
  config={{
    "document": {
      "fileType": "docx",
      "key": "Khirz6zTPdfd7",
      "title": "Example Document Title.docx",
      "url": "https://example.com/url-to-example-document.docx"
    },
    "documentType": "word",
    "editorConfig": {
      "callbackUrl": "https://example.com/url-to-callback.ashx"
    }
  }}
  events_onDocumentReady={onDocumentReady}
/>
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
上次更新: 2023/12/27