【问题标题】:How to import Ant Design css styles in GlobalStyles of styled-components.?如何在 styled-components 的 GlobalStyles 中导入 Ant Design css 样式?
【发布时间】:2020-05-07 23:25:00
【问题描述】:

如何在 styled-components 中导入 antd.css?而不是 App.css

@import '~antd/dist/antd.css';

整个目的是,我希望默认情况下来自 styled-components 的 GlobalStyles 具有所有 Ant Design 样式。

当我使用 AntD 中的元素时,它上面会包含所有默认类。

【问题讨论】:

    标签: reactjs antd styled-components


    【解决方案1】:

    You shouldn't.

    注意:目前我们建议不要在createGlobalStyle 中使用@import。我们正在努力为这个功能提供更好的行为,但它目前并没有真正起作用,如果你只是将这些导入嵌入到你的 HTML 索引文件等中会更好。

    你可以试试:

    import { createGlobalStyle, css } from 'styled-components';
    
    const antdCss = css`
      ${import('antd/dist/antd.css')}
    `;
    
    const GlobalStyle = createGlobalStyle`
      ${antdCss}
    `;
    
    export default GlobalStyle;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-11
      • 2021-06-02
      • 1970-01-01
      • 2020-02-14
      • 2021-08-26
      • 2017-11-19
      • 2019-10-23
      • 1970-01-01
      相关资源
      最近更新 更多