简体   繁体   English

从不使用类名和映射的模块导入反应 css

[英]import react css from modules not working with Classname and mapping

I'm using the.modules.css to style this component of a navigation menu我正在使用 .modules.css 来设置导航菜单的这个组件的样式

I have brought in the className via mapping over the array in a seperate file by accessing item.cNname我已经通过访问 item.cNname 通过映射到单独文件中的数组来引入 className

The question is how do I access the style module from here?问题是如何从这里访问样式模块? using style.item.cName does not work.使用 style.item.cName 不起作用。 any help would be great thank you任何帮助都会非常感谢

import style from "./MainNavigation.module.css";

          {MenuItems.map((item, index) => {
            return (
              <li key={index}>
                <a className={item.cName} href={item.url}>
                  {item.title}
                </a>
              </li>
            );   
          })}
        </ul>

/////////////////////////////////////////////////////

Array of menu menu item <a>

 export const MenuItems = [
    {
        title: 'Jobs',
        url: '/',
        cName: 'navLinks'
    },
    {
        title: 'Employers',
        url: '/',
        cName: 'navLinks'
    },
    {
        title: 'Get Connected',
        url: '/',
        cName: 'navLinks'
    },
    {
        title: 'About Us',
        url: '/',
        cName: 'navLinks'
    },
    {
        title: 'Contact Us',
        url: '/',
        cName: 'navLinks'
    },
] ```

import "./MainNavigation.module.css";导入“./MainNavigation.module.css”;

try like this:试试这样:

import style from "./MainNavigation.module.css";从“./MainNavigation.module.css”导入样式;

      {MenuItems.map((item, index) => {
        return (
          <li key={index}>
            <a className={`style.${item.cName}`} href={item.url}>
              {item.title}
            </a>
          </li>
        );   
      })}
 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM