【发布时间】:2020-09-12 16:57:46
【问题描述】:
我是 Web 开发新手,这只是我创建的一个简单代码,用于测试我安装的新文本编辑器,我在尝试导入 react 时遇到此错误,因为我遇到了一些其他错误,例如; TypeError:无法读取未定义的属性“createElement”
请问,我该如何解决?导入语句错了吗?
import React, { Fragment } from 'react';
console.log("Testing");
var document;//made this declaration because I got a document undefined error
document.createElement("p"):
const p = document.createElement("p")
p.innerHTML = "This is to test the javascript";
const body = document.querySelector("body");
body.insertBefore(p,body.childNode[-1]);
<!DOCTYPE html>
<html>
<head>
<title>Testing vs code</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
<h1>Testing the vscode html preview package</h1>
<h2>Hello</h2>
<script type="module" src="js-prac.js"></script>
</body>
</html>
【问题讨论】:
-
代码看不懂,你用的是react js还是想用简单的javascript?
-
我想用一个简单的javascript
-
那你为什么要导入 React?
标签: javascript html reactjs dom