首页 > 解决方案 > 如何在 html 中使用 React Component Ant Desing

问题描述

我正在寻求你的帮助。我的任务很简单。我通过 CDN(没有 Node js 服务器)和 Ant Design CDN 使用 React。我需要在我的 React App 中使用 Ant Design 组件。但是,它根本不适合我。我记得,几个月前我做过,但现在我无法复制它。下面是我的代码。Chrome 控制台说

Panel.js:272 Uncaught TypeError: moment__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function
    at Module../node_modules/_rc-time-picker@3.7.2@rc-time-picker/es/Panel.js (Panel.js:272)
    at __webpack_require__ (bootstrap:19)
    at Module../components/date-picker/wrapPicker.tsx (antd.js:9472)
    at __webpack_require__ (bootstrap:19)
    at Module../components/date-picker/index.tsx (antd.js:9344)
    at __webpack_require__ (bootstrap:19)
    at Module../components/index.tsx (index.tsx:1)
    at __webpack_require__ (bootstrap:19)
    at Object../index.js (index.js:25)
    at __webpack_require__ (bootstrap:19)
Cannot read property 'Button' of undefined

我用谷歌搜索了这个问题,显然浏览器无法识别 require(import) 命令。我真诚地请求你的帮助。谢谢!

<!doctype html>
<html lang="en-us">
  <head>

    <!-- React CNDs -->
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.js'></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js'></script>

    <!-- Material Design CDNs-->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
    <!-- <script type="module" src="https://unpkg.com/@material-ui/core@4.4.3/umd/material-ui.production.min.js"></script>  -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/antd/3.23.4/antd.js" integrity="sha256-x4ITqB7m84o5/YGY7vx7hmRvoWj/Yj7Zm4+Yxipq+r0=" crossorigin="anonymous"></script>
  </head>
  <body>


    <div id="root"></div>

    <script type="text/babel">
    const {Button} = window['antd']

        class App extends React.Component {

            render() {

              return (
                <Button type="primary">
                  Test
                </Button>
              );
            }
          }
    ReactDOM.render(<App />, document.getElementById('root')); 
    </script>
  </body>
</html>

标签: reactjsbabeljsantd

解决方案


按照这个示例项目。导入的方式有所不同。


推荐阅读