[英]Integrate GrapesJS with React JS
I am trying to integrate GrapesJS Feature with my React APP.我正在尝试将 GrapesJS 功能与我的 React APP 集成。
I get an error while implementing like `Uncaught TypeError: Cannot read property 'forEach' of undefined grapesjs react`
I would like to have a feature like in this URL
https://grapesjs.com/demo.html
npm i grapesjs-react
import React, {Component} from 'react';
import GEditor from 'grapesjs-react';
class GEditorExample extends Component {
render() {
return (
<GEditor/>
);
}
}
export default GEditorExample;
Any help would be great.任何帮助都会很棒。 Thank You.*谢谢你。*
You've to specify the blocks prop to , this block will be added to the editor by blockmanager.add
method of grapes-js.您必须将 blocks blockmanager.add
指定为 ,此块将通过葡萄 js 的blockmanager.add
方法添加到编辑器中。 If there is no need for a block, try giving an empty array, like:如果不需要块,请尝试提供一个空数组,例如:
<GEditor id="gjs" blocks={[]} />
if You pass blocks to GEditor, It will work.如果您将块传递给 GEditor,它将起作用。
See the sample code below请参阅下面的示例代码
import React, {Component} from 'react';
import GEditor from 'grapesjs-react';
class GEditorExample extends Component {
render() {
return (
<GEditor id="geditor" blocks={[]}/>
);
}
}
export default GEditorExample;
Which version of grapesjs-react are you using?您使用的是哪个版本的grapesjs-react? I configured the default value for blocks
props:我为blocks
props 配置了默认值:
GEditor.defaultProps = {
blockManager: {},
blocks: [],
components: [],
newsletter: false,
plugins: [],
storageManager: {},
styleManager: {},
webpage: false,
};
Try to update the package to the newest version if you still got this error.如果仍然出现此错误,请尝试将软件包更新到最新版本。
I have been looking for a good integrator for a while.我一直在寻找一个好的集成商一段时间。 Currently, my solution is to use <iframe>
to load GrapeJS from an external file server.目前,我的解决方案是使用<iframe>
从外部文件服务器加载 GrapeJS。 For example: using an iframe inside a React component like this:例如:在 React 组件中使用 iframe,如下所示:
<iframe height="100%" src={`http://127.0.0.1:8081/templateId=${templateId} title="Build your own template" width="100%" />
I know it's not a good solution, but currently its the only method I found to be workable with my problem.我知道这不是一个好的解决方案,但目前它是我发现可以解决我的问题的唯一方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.