amis icon indicating copy to clipboard operation
amis copied to clipboard

在 React 原生项目中引入amis编辑器报错

Open user-huage opened this issue 4 years ago • 1 comments

实现场景:

在React 原生项目中引入amis编辑器组件来使用editor

代码展示:

import React from 'react';
import { Editor } from 'amis-editor';

function App(props : any) {

  let store = {
    preview: false,
    schema: { body: 'aaa', title: "Hello world", type: "page" },
    updateSchema: (value: string) => { console.log("updateSchema方法执行了") },
    isMobile: false
  }
  let schemaUrl = "/schema.json"
  let iframeUrl = "/editor.html"

  let host = `${window.location.protocol}//${window.location.host}`;
  // 如果在 gh-pages 里面
  if (/^\/amis-editor-demo/.test(window.location.pathname)) {
    host += '/amis-editor';
    iframeUrl = '/amis-editor-demo' + iframeUrl;
  }

  return (
      <Editor
        theme={'cxd'}
        preview={store.preview}
        value={store.schema}
        onChange={(value: any) => store.updateSchema(value)}
        className="is-fixed"
        $schemaUrl={schemaUrl}
        iframeUrl={iframeUrl}
        isMobile={store.isMobile}
      />
  )
}
export default App;

报错:

image image

code here...

user-huage avatar Dec 16 '21 06:12 user-huage

感觉可能是 react 和 react dom 版本不一样,参考 https://github.com/aisuda/amis-editor-demo 项目

nwind avatar Dec 28 '21 06:12 nwind