在我的Next.js项目中,我正在用TailWind CSS做圆圈,这样我就可以有不同状态的switch .

interface Status {
  status: "online" | "offline" | "idle" | "dnd";
}
const StatusCircle = ({ status }: Status) => {
  return (
    <>
      <div className="flex items-center justify-center">
        <div
          className={`m-3 flex h-40 w-40 items-center justify-center rounded-full ${
            status == "online"
              ? "bg-green-500"
              : status == "offline"
              ? "bg-gray-500"
              : status == "idle"
              ? "bg-orange-400"
              : status == "dnd"
              ? "bg-red-500"
              : "bg-gray-500"
          }`}
        ></div>
      </div>
    </>
  );
};

export default StatusCircle;

这是在尾风playground 工作的圆圈的代码.我把它粘贴到我的页面上,但我的页面不会只是一个圆形,所以我试图将这个圆形作为一个组件,并将其import粘贴到页面中,这是:

import StatusCircle from "@/components/StatusCircle";

const Page = () => {
  return (
    <>
      <StatusCircle status="online" />
      <div className="m-3 flex h-2 w-2 items-center justify-center rounded-full bg-red-500"></div>
    </>
  );
};

export default Page;

当我在dev工具中查看时,我确实有组件,但它没有显示为一个圆圈.

After I changed the state and test, only "dnd" is shown enter image description here but not "idle", "offline" and "online" even though the tailwind is correct

推荐答案

来自@Dennis-Martinez "判断tailwind 配置文件的Content部分.确保包括组件目录.tawincss.com/docs/Content-configuration"

在您的根文件夹中,应该有一个用于设置tailwind 配置的Tailwind.config.js

module.exports = {
  content: [
    "./src/pages/**/*.{js,ts,jsx,tsx}",
    "./src/components/**/*.{js,ts,jsx,tsx}", // make sure you have this
  ],
}

如果您也遇到相同的错误,请确保您已在内容字段中注册了组件:)

Reactjs相关问答推荐

包装组件可以避免子组件重新渲染.?

useTranslation不会在languageChanged上重新呈现组件

我想删除NextJs中的X轴标签APEXCHARTS

Tailwind不使用@apply classes构建,并强制使用类似于移动的viewport

下拉Tailwind CSS菜单与怪异beviour

在React Create App TS项目中安装material UI

如何使图像zoom 并移动到点击点

为什么查询错误在处理后仍出现在控制台中?RTK查询+ React

Mantine DatePickerInput呈现错误

useMemo 依赖项的行为

useRef.current.value 为空值

如何在 JS 中绘制具有不同笔画宽度的样条线

如何覆盖自定义 MUI 手风琴的样式(分隔线和折叠图标)

导入样式化组件时未导入组件内容

antd 找不到 comments

我正在try 使用 cypress 测试我的下拉列表,它 Select 值但不提交它们(手动工作)

SonarCloud 代码覆盖率不适用于 Github Action

react-markdown 不渲染 Markdown

如何在 React JS 上使文本中的单词可点击

我在使用 Elements of stripe 时使用 React router v6