【问题标题】:Materialui - where to load CSS classes from?Material Ui - 从哪里加载 CSS 类?
【发布时间】:2020-06-30 04:12:01
【问题描述】:

这可能有一个快速的答案。我开始学习 Material UI 并想尝试它的网格示例,但下面的编码提到编译拒绝为 NOTFOUND ..找不到要加载的 CSS 文件来尝试这些示例..没有 className 参数,我看不到任何大纲GRID 的,所以这些 css 'classes.root' 可能包含格式化选项。感谢您的热心帮助,

function App() {
return (
    <div className={classes.root}>  ????
      <Grid container spacing={3}>
        <Grid item xs={12}>

【问题讨论】:

  • 从您粘贴的代码中不清楚是否定义了classes.root。你能粘贴整个 App.js 文件吗?
  • app.js 什么都没有.. 找不到要为 materialui 网格加载的 CSS 文件
  • 您在上面粘贴了一半的 javascript 文件。请粘贴整个文件以及您看到的确切错误消息。
  • @jmknoll 我不得不发布一个新问题,因为评论不允许发布整个代码。stackoverflow.com/questions/62662275/…

标签: css reactjs material-ui


【解决方案1】:

你需要使用makeStyles

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles({
  root: {
    backgroundColor: 'red',
    color: props => props.color,
  },
});

function App(props) {
  const classes = useStyles(props);
  return (
    <div className={classes.root}>
      // ...
    </div>
  );
}

【讨论】:

  • ``` 从“react”导入反应;从“@material-ui/core”导入 MenuIcon; function Materialuig(){ const useStyles = makeStyles({ root: { backgroundColor: "red", color: (props) => props.color, }, });常量类 = useStyles(props); return (
    xs=12
    ); } 导出默认 Materialuig; ```
  • 以上是我根据您的建议尝试的代码,但出现错误“未定义道具。 “纸”未定义。 从 index.js 调用
  • 发布一个新问题,因为评论部分没有空间可以发布整个代码
猜你喜欢
  • 2020-10-21
  • 2019-05-20
  • 2010-09-18
  • 1970-01-01
  • 2020-09-30
  • 2021-07-17
  • 1970-01-01
  • 2016-06-16
相关资源
最近更新 更多