【问题标题】:ReactJS with CoffeeScript with Rails ReferenceError: <component> is not definedReactJS with CoffeeScript with Rails ReferenceError: <component> is not defined
【发布时间】:2015-04-29 09:18:54
【问题描述】:

我刚开始学习 ReactJS,从一开始我就有问题! 正如我所看到的,你说 React 与咖啡一起工作。 我的文件 hello.js.jsx.coffee

HelloWorld = React.createClass
  render: ->
    `<div>
      <h1>Hello World!</h1>
    </div>`

在我看来:

= react_component('HelloWorld', {}, :span)

但我得到错误:

ReferenceError: HelloWorld 未定义

我的应用示例是:

https://github.com/olegsobchuk/example_app

我使用的是 Rails 4.2。

【问题讨论】:

    标签: ruby-on-rails coffeescript reactjs


    【解决方案1】:

    所以,我找到了解决办法

    改为

    HelloWorld = React.createClass
      .....
    

    我们必须使用

    @HelloWorld = React.createClass
      render: ->
        `<div>
           <h1>Hello World!</h1>
         </div>`
    

    谢谢@rmosolgo!

    【讨论】:

      猜你喜欢
      • 2021-11-09
      • 2016-11-22
      • 2021-08-17
      • 2020-08-03
      • 2017-08-06
      • 2018-11-20
      • 2022-12-01
      • 2017-06-07
      • 2017-10-02
      相关资源
      最近更新 更多