Material UI按钮未显示

huangapple go评论55阅读模式
英文:

Material UI Button not displayed

问题

以下是您提供的代码的中文翻译部分:

index.js 中的内容:

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

App.js1 中的内容:

import Button from '@mui/material/Button';

function App() {
  return  <Button variant="contained">Button</Button>
}

export default App;

package.json 中的内容:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

请问还有其他需要帮助的地方吗?

英文:

Follow is my content of index.js

import React from &#39;react&#39;;
import ReactDOM from &#39;react-dom/client&#39;;
import App from &#39;./App&#39;;


const root = ReactDOM.createRoot(document.getElementById(&#39;root&#39;));
root.render(
  &lt;React.StrictMode&gt;
    &lt;App /&gt;
  &lt;/React.StrictMode&gt;
);

App.js1

import Button from &#39;@mui/material/Button&#39;;

function App() {
  return  &lt;Button variant=&quot;contained&quot;&gt;Button&lt;/Button&gt;
}

export default App;

package.json

{
  &quot;name&quot;: &quot;my-app&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;private&quot;: true,
  &quot;dependencies&quot;: {
    &quot;@emotion/react&quot;: &quot;^11.10.6&quot;,
    &quot;@emotion/styled&quot;: &quot;^11.10.6&quot;,
    &quot;@testing-library/jest-dom&quot;: &quot;^5.16.5&quot;,
    &quot;@testing-library/react&quot;: &quot;^13.4.0&quot;,
    &quot;@testing-library/user-event&quot;: &quot;^13.5.0&quot;,
    &quot;react&quot;: &quot;^18.2.0&quot;,
    &quot;react-dom&quot;: &quot;^18.2.0&quot;,
    &quot;react-scripts&quot;: &quot;5.0.1&quot;,
    &quot;web-vitals&quot;: &quot;^2.1.4&quot;
  },
  &quot;scripts&quot;: {
    &quot;start&quot;: &quot;react-scripts start&quot;,
    &quot;build&quot;: &quot;react-scripts build&quot;,
    &quot;test&quot;: &quot;react-scripts test&quot;,
    &quot;eject&quot;: &quot;react-scripts eject&quot;
  },
  &quot;eslintConfig&quot;: {
    &quot;extends&quot;: [
      &quot;react-app&quot;,
      &quot;react-app/jest&quot;
    ]
  },
  &quot;browserslist&quot;: {
    &quot;production&quot;: [
      &quot;&gt;0.2%&quot;,
      &quot;not dead&quot;,
      &quot;not op_mini all&quot;
    ],
    &quot;development&quot;: [
      &quot;last 1 chrome version&quot;,
      &quot;last 1 firefox version&quot;,
      &quot;last 1 safari version&quot;
    ]
  }
}

And you can see in the following picture, nothing is displayed (supposedly to display a button):
Material UI按钮未显示

How should I solve this?

答案1

得分: 1

你还没有安装 MUI 库,请按照文档进行安装:

npm install @mui/material

英文:

You have not installed the MUI library, follow the document and install this:

npm install @mui/material

答案2

得分: 1

请按照文档安装Material UI。

第一步,请尝试:

npm install @mui/material @emotion/react @emotion/styled

然后,导入@font

npm install @fontsource/roboto

添加到index.js

import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';

如果您想要使用Material UI的图标,请尝试:

npm install @mui/icons-material

希望对您有所帮助。

英文:

Please follow the documentation to install Material UI.

First, try:

npm install @mui/material @emotion/react @emotion/styled

Then, import @font

npm install @fontsource/roboto

Add to index.js

import &#39;@fontsource/roboto/300.css&#39;;
import &#39;@fontsource/roboto/400.css&#39;;
import &#39;@fontsource/roboto/500.css&#39;;
import &#39;@fontsource/roboto/700.css&#39;;

And if you want to using icon of Material UI, try:

npm install @mui/icons-material

Hope that help

huangapple
  • 本文由 发表于 2023年2月26日 22:17:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定