1

我正在设计我的反应应用程序。我正在使用带有 webpack 的 css 模块。这是我的配置:

{ test: /\.css$/, loaders: ["style", "css?modules"] },

我设计了我的组件,煮了一杯咖啡,但现在它不工作了。所以我有一个我想使用的样式表。我正在导入它:

import styles from "./search.css";

但是,当我打破我的组件时,styles没有定义。我的样式现在都没有被应用。这是我如何使用它的示例:

// the chrome inspector only shows the first two styles, the last is not there
<div className={["col-md-2", "col-lg-1", styles.startTimes]}>

为什么会styles是空的?

4

1 回答 1

2

终于搞定了。这不是正确的语法:

<div className={["col-md-2", "col-lg-1", styles.startTimes]}>

你让你使用classNames而不是:

<div className={cx("col-md-2", "col-lg-1", styles.startTimes)}>

您还需要只在 CSS 中使用类名。如果您直接设置标签名称(h1等),则这些名称不会在本地应用。

于 2016-01-14T20:14:00.757 回答