未捕获的引用错误:未定义 mountNode

2024-02-19

请原谅我,我已经到处搜索过,而且我是reactjs 的新手并正在尝试示例。我有一个错误

Uncaught ReferenceError: mountNode is not defined 

我正在按照这里的例子http://facebook.github.io/react/tips/initial-ajax.html 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 />成分。您可能想要更换mountNode with document.getElementById('example')参考你的<div id="example"></div>元素:

React.render(
  <UserGist source="https://api.github.com/users/octocat/gists" />,
  document.getElementById('example')
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未捕获的引用错误:未定义 mountNode 的相关文章