【发布时间】:2022-01-15 12:51:49
【问题描述】:
JS:
import React from "react";
import { ReactDOM } from "react";
import './style.css';
import App2 from "./App2.js";
function App() {
return (
<App2.js />
)
}
ReactDOM.render(<App />, document.getElementById('root'))
上述文件中引用的App2.js:
import React from "react";
import { ReactDOM } from "react";
export default function App2() {
return (
<div>
<h1>Yusif Ahmedov</h1>
<button id="email"></button>
<button id="linkedin"></button>
<h2>Front-End Developer</h2>
<header id="about-header">About</header>
<p id="about">I am a front-end developer who is passionate about coding and engaging both creative and practical side of the human potential.</p>
<header id="interests-header">Interests</header>
<p id="interests">Productivity articles, Time Management, Coffee, Music, Sports, Social Activities.</p>
</div>
)
}
还有简单的 HTML:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Card</title>
<script type="module" src="./App.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
我都是从头开始写的,所以没有多余的文件。 当我运行它时,它给出了一个错误: Uncaught SyntaxError: Unexpected token '
我不明白为什么它在第 8 行给出错误。
【问题讨论】:
-
不应该是
<App2 />没有.extension!? -
@luk2302 应该的。
-
JSX 是 JavaScript 的扩展。检查您的 JSX 解析器/转译器(例如 Babel)是否设置正确。
标签: javascript reactjs