【问题标题】:How to override antd style with dva如何用 dva 覆盖 antd 样式
【发布时间】:2017-12-02 17:35:11
【问题描述】:

我用 dva 初始化了我的项目

// component.js
import React from 'react';
import { Table, Icon } from 'antd';
import styles from '../../style/public.less';
import comStyle from '../../style/company.less';

// company.less
.ant-table {
    border: none!important;
}

我的风格像这样被“模块化”ant-table-small___2ihaB 如何覆盖内置类?

【问题讨论】:

  • 禁用 css 模块。
  • @yesmeck 感谢您的回复,所以没有官方的方法可以绕过它?太烂了。。

标签: reactjs antd react-css-modules


【解决方案1】:

最后,一位同事帮我解决了这个问题——这个答案是:global,这将覆盖全局的内置样式。像这样:

:global {
  .ant-table {
    border: none;
  }
}

如果您不想全局覆盖它,只需将 :global 嵌套在您的类中,然后将该类提供给您要设置样式的组件。

示例:

// myStyle.less
.myClass {
  :global {
    .ant-table {
      border: none;
    }
  }
}
// myComponent.js
<Table className={styles.myClass} />

【讨论】:

    猜你喜欢
    • 2019-10-31
    • 2019-09-28
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    • 2020-05-22
    • 2019-09-01
    • 2015-06-22
    相关资源
    最近更新 更多