简体   繁体   English

React JS - React Material UI 图标不起作用?

[英]React JS - React Material UI icons not working?

I am using react Material UI, and I received the following error.我正在使用 React Material UI,但收到以下错误。

"Module not found: Can't resolve '@material-ui/icons/Lock'" “未找到模块:无法解析‘@material-ui/icons/Lock’”

import LockIcon from '@material-ui/icons/Lock';

How can I fix this?我怎样才能解决这个问题?

import Icon from '@material-ui/core/Icon';

然后将字体材质图标添加到index.html

<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

You haven't installed @material-ui/icons package. 您尚未安装@material-ui/icons包。 You can validate it from node_modules 您可以从node_modules验证它


This would resolve your issue, 这可以解决您的问题,

npm install --save @material-ui/icons

MUI have since separated their icons from core into a separate node_module called @material-ui/icons . MUI 已经将他们的icons从核心分离到一个名为@material-ui/icons的单独 node_module 中。

Here's a good example on how to setup your MUI Icons with React: https://mechanicalrock.github.io/2021/04/27/fed-talk-s01e01-getting-started#keyboard-getting-started-with-material-ui这是一个关于如何使用 React 设置 MUI 图标的好例子: https : //mechanicalrock.github.io/2021/04/27/fed-talk-s01e01-getting-started#keyboard-getting-started-with-material-用户界面

Here's an alternative is you cant install the node modules:这是您无法安装节点模块的替代方法:

  1. Add "" to your head tag, or whever you store your links to style sheets.将 "" 添加到您的 head 标签,或者您将链接存储到样式表的任何地方。
  2. Add a span tag with class name "material-icons" and make the content of the span the icon you want to use.添加类名为“material-icons”的 span 标签,并使 span 的内容成为您要使用的图标。 example: menu示例:菜单

You can find more info about all the icons here您可以在此处找到有关所有图标的更多信息

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

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