【问题标题】:Using react_component() to add react components in haml files使用 react_component() 在 haml 文件中添加反应组件
【发布时间】:2021-02-07 21:27:51
【问题描述】:

在使用react-rails 库时,我们可以使用.erb 文件中的react_component() 函数来添加反应组件。

我们如何在.haml 文件中使用相同的函数?还是我们有另一种方法可以在 haml 文件中添加 react 组件?

【问题讨论】:

    标签: ruby-on-rails reactjs haml react-rails


    【解决方案1】:

    如果您的 RoR 项目中设置了 webpacker,那么您可以简单地使用来自 react-railsreact_component 函数,就像我们将 ruby​​ 代码添加到 haml 文件一样。

    例如:

    %li
      = react_component("ReactComponent")
    

    这应该可以正常工作。默认情况下,Webpacker 会尝试在 app/javascript/components 中定位 React 组件。

    【讨论】:

      猜你喜欢
      • 2021-04-21
      • 2017-12-14
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 2019-11-11
      • 1970-01-01
      相关资源
      最近更新 更多