繁体   English   中英

未捕获ReferenceError:未定义$(反应)?

[英]Uncaught ReferenceError: $ is not defined (react)?

您好,我正在关注有关学习React的教程,并且一口气收到了未定义的参考错误。 我正在本地调用所有依赖库,所以我认为hte库未完全加载不是问题。 我是React的新手,所以我不确定问题是什么

我尝试重命名变量,并仔细检查了所有类似的问题,并在此处发布了参考错误

<div id="entry-point"></div>

<script src="lib/react.js"></script>
<script src="lib/react-dom.js"></script>
<script src="lib/babel.js"></script>    

<script>
 console.log('notes')       
        let notes = [
          { id: 1, content: "Learn React" },
          { id: 2, content: "Get Lunch" },
          { id: 3, content: "Learn React Native" }
        ]

        class Note extends React.Component {
          render() {
            return React.createElement("li", {}, this.props.content)
          }
        }

        class NotesList extends React.Component {
          renderNote(note) {
            return React.createElement(Note, { key: note.id, content: note.content })
          }
          render() {
            let { notes } = this.props

            return React.createElement("ul", {}, notes.map(this.renderNote, this))
          }
        }

        class App extends React.Component {
          render() {
            let { notes } = notes

            return React.createElement(
              "section",
              {},
              React.createElement("h1", {}, "You have ", notes.length, " notes"),
              React.createElement(NotesList, { notes: notes })
            )
          }
        }

        ReactDOM.render(
          React.createElement(App, { notes: notes }),
          document.getElementById("entry-point")
        )
</script>

这是我收到的错误消息:

ReferenceError: Cannot access 'notes' before initialization
    at App.render (scratch.html:47)
    at h (react-dom.js:130)
    at beginWork (react-dom.js:134)
    at d (react-dom.js:158)
    at f (react-dom.js:159)
    at g (react-dom.js:159)
    at t (react-dom.js:167)
    at x (react-dom.js:166)
    at r (react-dom.js:164)
    at v (react-dom.js:163)

ReferenceError:在App.render初始化之前无法访问“注释”(scratch.html:47)

因此,您的编译器会告诉您问题出在哪里,在这种情况下,渲染函数位于第47行。

然后,它告诉您在初始化之前无法访问。 您正在尝试使用以下语法进行重构:

    let { notes } = notes

本质上是在说“让便笺= notes.notes;”。 由于notes是一个数组,并且没有名为notes的属性-您收到错误。 您已经在范围中定义了注释,因此请尝试删除该行并查看会发生什么。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM