javascript 如何导入 Material ui 图标? 我在使用 Material ui 图标时遇到了一些问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49769639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 08:45:25  来源:igfitidea点击:

how to import material ui icons?i met some problems using Material ui icons

javascriptreactjsmaterial-ui

提问by WEN-JY

I was using material UI with react in my project,and i have some troubles when it come to import the material icons,my code is copied from the material UI (version:"material-ui": "^1.0.0-beta.41", "material-ui-icons": "^1.0.0-beta.36",) docs ,just like this:

我在我的项目中使用了带有 react 的材质 UI,在导入材质图标时遇到了一些麻烦,我的代码是从材质 UI 复制的(版本:“material-ui”:“^1.0.0-beta. 41", "material-ui-icons": "^1.0.0-beta.36",) 文档,就像这样:

import SkipPreviousIcon from '@material-ui/icons/SkipPrevious';
import PlayArrowIcon from '@material-ui/icons/PlayArrow';
import SkipNextIcon from '@material-ui/icons/SkipNext';

and also i have run npm install material-icons. the error in my chrome console is:

而且我还运行了 npm install material-icons。我的 chrome 控制台中的错误是:

./src/index/musicCard.js Module not found: Can't resolve '@material-ui/icons/PlayArrow' in 'C:\Users\wenji\Desktop\myblog\src\index' and I tried this one:

./src/index/musicCard.js Module not found: Can't resolve '@material-ui/icons/PlayArrow' in 'C:\Users\wenji\Desktop\myblog\src\index' 我试过这个:

import SkipPreviousIcon from 'material-ui/icons/SkipPrevious';

and this one:

还有这个:

import SkipPreviousIcon from '@material-ui-icons/SkipPrevious';

but dose not make any difference,so can anyone help me ?

但没有任何区别,所以有人可以帮助我吗?

回答by Neeraj Bansal

Icons are not part of material-ui/core so it must be install using two commands.

图标不是 material-ui/core 的一部分,因此必须使用两个命令安装它。

If you are using npm

如果你使用 npm

npm install @material-ui/core
npm install @material-ui/icons

If you are using yarn

如果你使用纱线

yarn add @material-ui/core
yarn add @material-ui/icons

回答by WEN-JY

Solved, the icons module should be added to dependencies. use npm

解决了,应该将图标模块添加到依赖项中。使用 npm

npm install @material-ui/icons 

or use yarn

或使用纱线

yarn add @material-ui/icons