加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

应用程序崩溃在Meteor React.js教程的第2部分

发布时间:2020-12-15 20:12:28 所属栏目:百科 来源:网络整理
导读:我的应用程序在Meteor React.js tutorial中崩溃(下面).我似乎无法找到问题,代码完全来自教程.救命! Desktop/simple-todos-react/.meteor/local/build/programs/server/app/simple-todos-react.js:14 React.render(App /,document.getElementById("render-ta
我的应用程序在Meteor React.js tutorial中崩溃(下面).我似乎无法找到问题,代码完全来自教程.救命!

Desktop/simple-todos-react/.meteor/local/build/programs/server/app/simple-todos-react.js:14
    React.render(<App />,document.getElementById("render-target"));   // 6
                 ^
SyntaxError: Unexpected token <
    at Desktop/simple-todos-react/.meteor/local/build/programs/server/boot.js:241:30
    at Array.forEach (native)
    at Function._.each._.forEach (/.meteor/packages/meteor-tool/.1.1.9.1u3q681++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
    at /Desktop/simple-todos-react/.meteor/local/build/programs/server/boot.js:137:5
Exited with code: 8
Your application is crashing. Waiting for file change.

简单待办事项,react.html

<head>
  <title>Todo List</title>
</head>

<body>
  <div id="render-target"></div>
</body>

简单待办事项,react.js

if (Meteor.isClient) {
  // This code is executed on the client only

  Meteor.startup(function () {
    // Use Meteor.startup to render the component after the page is ready
    React.render(<App />,document.getElementById("render-target"));
  });
}

App.jsx

// App component - represents the whole app
App = React.createClass({
  getTasks() {
    return [
      { _id: 1,text: "This is task 1" },{ _id: 2,text: "This is task 2" },{ _id: 3,text: "This is task 3" },{ _id: 4,text: "This is task 4" },{ _id: 5,text: "This is task 5" }
    ];
  },renderTasks() {
    return this.getTasks().map((task) => {
      return <Task key={task._id} task={task} />;
    });
  },render() {
    return (
      <div className="container">
        <header>
          <h1>Todo List</h1>
        </header>

        <ul>
          {this.renderTasks()}
        </ul>
      </div>
    );
  }
});

Task.jsx

// Task component - represents a single todo item
Task = React.createClass({
  propTypes: {
    // This component gets the task to display through a React prop.
    // We can use propTypes to indicate it is required
    task: React.PropTypes.object.isRequired
  },render() {
    return (
      <li>{this.props.task.text}</li>
    );
  }
});

解决方法

哇,忘了在文件名末尾添加“x”.应该是“simple-todos-react.jsx”.如果错误消息更清楚,将有所帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读