本文介绍了未捕获的ReferenceError:未定义mountNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
原谅我到处搜索,我是reactjs的新手,并尝试了一些示例.我有一个错误
forgive me i've searched everywhere and I'm new in reactjs and trying out examples. I have an error
Uncaught ReferenceError: mountNode is not defined
我从此处遵循示例 http://facebook.github.io/react/tips/initial-ajax.html
我的代码看起来像这样
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="/javascripts/reactjs/react.js"></script>
<script src="/javascripts/reactjs/JSXTransformer.js"></script>
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
<div id="example"></div>
<script src="/javascripts/reactjs/build/helloworld.js"></script>
<script type="text/jsx">
/** @jsx React.DOM */
var UserGist = React.createClass({
getInitialState: function() {
return {
username: '',
lastGistUrl: ''
};
},
componentDidMount: function() {
$.get(this.props.source, function(result) {
var lastGist = result[0];
this.setState({
username: lastGist.owner.login,
lastGistUrl: lastGist.html_url
});
}.bind(this));
},
render: function() {
return (
<div>
{this.state.username}last gist is
<a href={this.state.lastGistUrl}>here</a>.
</div>
);
}
});
React.renderComponent( <UserGist source="https://api.github.com/users/octocat/gists" />, mountNode );
</script>
</body>
</html>
提前谢谢!
推荐答案
您需要告诉React在哪里安装<UserGist />
组件.您可能想用document.getElementById('example')
替换mountNode
来引用您的<div id="example"></div>
元素:
You need to tell React where to mount the <UserGist />
component. You probably want to replace mountNode
with document.getElementById('example')
to refer to your <div id="example"></div>
element:
React.render(
<UserGist source="https://api.github.com/users/octocat/gists" />,
document.getElementById('example')
);
这篇关于未捕获的ReferenceError:未定义mountNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!