【发布时间】:2019-09-20 04:52:40
【问题描述】:
此代码在本地运行时运行良好。当我在000webhost 中上传它并在 WordPress 页面中使用 bundle.js 的路径时,就会遇到这个错误。
我在没有_registerComponent 的情况下收到上述错误。到处都有_registerComponent 错误的解决方案。
我也将document.getElementById("app") 的值设为空。
app.js
import React from "../node_modules/react/index";
import { render } from "../node_modules/react-dom/index";
import Plans from "./components/Plans";
//Import CSS
import "./styles/styles.scss";
const App = () => (
<div>
<Plans/>
</div>
);
var app = document.getElementById("app");
console.log("app",document.getElementById("app"))
render(<App/>, app);
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script src="./bundle.js"></script>
</body>
</html>
Code used in WordPress
<html>
<head>
</head>
<body>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script async src="https://unvisitable-bows.000webhostapp.com/react-widget-subscription-plans/react-widget-subscription-plans/public/bundle.js" crossorigin></script>
</body>
</html>
【问题讨论】:
-
请any of these帮忙?并非所有这些都与
_registerComponent -
这行代码
app是什么render(<App/>, app) -
抱歉,我错过了粘贴 var app = document.getElementById("app");
标签: javascript reactjs wordpress