【问题标题】:suneditor-react Typescript getContent is not workingsuneditor-react Typescript getContent 不起作用
【发布时间】:2021-05-22 14:50:24
【问题描述】:
我正在使用 suneditor-react 和 typescript。我想获取编辑器的内容创建 PDF。但问题是当我尝试访问 SunEditor 的 ref 时,出现以下错误
Property 'ref' does not exist on type 'IntrinsicAttributes & SunEditorReactProps & { children?: ReactNode; }'.
此外,我在SunEditorReactProps 中也找不到getContents() 道具。但它在他们的示例页面中。
请提出你的想法。
sunediotr-react
suneditor example page
【问题讨论】:
标签:
reactjs
typescript
suneditor
【解决方案1】:
您好,我是 SunEditor React 组件的作者,您可以学习如何将 ref 附加到 suneditor react 组件(在 typescript 中)here。
【解决方案2】:
- 导入 SuneditorCore
import SunEditorCore from "suneditor/src/lib/core";
2)给定变量的声明和设置值
private suneditor1!:SunEditorCore;
this.suneditor1=suneditor.create('sample', {
});
3)调用 suneditor 函数
const savedata=this.suneditor1.getContents(true);