代码之家  ›  专栏  ›  技术社区  ›  sudo bangbang

使用ANTD创建React应用程序

  •  2
  • sudo bangbang  · 技术社区  · 7 年前

    我试着用 antd 具有 create react app .

    我在项目中安装了Antd

    yarn add antd
    

    使用ANTD的按钮组件添加了一个按钮

    import React, { Component } from 'react';
    import Button from 'antd/lib/button';
    import './App.css';
    
    class App extends Component {
      render() {
        return (
          <div className="App">
            <Button type="primary">Button</Button>
          </div>
        );
      }
    }
    
    export default App;
    

    不过,按钮没有正确呈现。在检查元素时,我发现正在应用ANTD类。只是没有加载CSS。

    2 回复  |  直到 6 年前
        1
  •  2
  •   sudo bangbang    7 年前

    @import '~antd/dist/antd.css';
    
    .App {
      text-align: center;
    }
    

    antd's official docs for using with Create React App

    yarn add antd
    

    import React, { Component } from 'react';
    import Button from 'antd/lib/button';
    import './App.css';
    
    class App extends Component {
      render() {
        return (
          <div className="App">
            <Button type="primary">Button</Button>
          </div>
        );
      }
    }
    
    export default App;
    

        2
  •  1
  •   user158    6 年前

    import Button from 'antd/lib/button';
    import 'antd/lib/button/style/css'; // importing only the required CSS
    

    ant design docs https://github.com/ant-design/ant-design/issues/13274

    https://github.com/ant-design/ant-design/issues/12011