1

我正在为每个人系列寻找 LevelUpTuts Meteor+React。我有“ Uncaught Invariant Violation: _registerComponent(...): Target container is not a DOM element.”错误,但我不知道问题出在哪里。

client/Main.html
<head>
<title>myResolutions</title>
<meta charset="utf-8"/>
</head>

<body>
<div id="target-render"></div>
<script src="./App.js"></script
</body>

在我的 App.jsx

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

class App extends React.Component{
render() {
    return (
        <h1> Hello World </h1>
    )
}
}

if(Meteor.isClient){
Meteor.startup(function(){
    ReactDOM.render(<App />,document.getElementById("render-target"));
});
}
4

3 回答 3

1

看起来在 html 中您的 id 为“target-render”,而在 javascript 中您的 id 为“render-target”。他们需要匹配。

于 2016-08-01T14:57:11.280 回答
0

我想问题出在这条线上:

它不应该在这里。

我强烈建议您使用官方 Meteor 教程而不是其他任何东西: https ://www.meteor.com/tutorials/react/creating-an-app

于 2016-07-31T04:53:05.640 回答
0

首先,你需要 import Meteorimport { Meteor } from 'meteor/meteor';然后你不需要包含<script src="./App.js"></script>在你的 html 中。请注意,您在那一行有错字,您没有正确关闭脚本标签

于 2016-07-31T19:51:01.013 回答