【问题标题】:Use 'noty' js library in Rails 5在 Rails 5 中使用“noty”js 库
【发布时间】:2018-11-11 14:45:58
【问题描述】:

我正在尝试制作 noty.js (https://ned.im/noty/#/installation - 通知库)可以在我的 Rails 应用程序中使用。

我已经用 npm 安装了它

 npm install noty

现在,它出现在node_modules 下。 当我尝试使用

在 js 文件中对其进行测试时
new Noty({

    text: 'Some notification text'

}).show();

我会得到' Uncaught ReferenceError: Noty is not defined' 如果我尝试在我的 js 文件中导入它: import Noty from 'noty' ;我会得到'Uncaught SyntaxError: Unexpected identifier'(我的'noty'路径是可见的-我可以被引导到它)。

我怎样才能让它正常工作?

【问题讨论】:

  • 你在使用 webpack 吗?
  • @DanielWestendorf No.

标签: javascript jquery ruby-on-rails ruby npm


【解决方案1】:

如果您没有使用 webpack 或其他一些 JS 资产管理系统,则使用 NPM 安装将无法正常工作。你需要

  1. 下载noty.cssnoty.js,放在各自的assets目录下
  2. 将它们添加到您的assets.rb
  3. 重启服务器
  4. 在您的 application.js 之前在您的布局中引用该文件

阅读Asset Pipeline 上的指南了解更多详情。

<%= stylesheet_link_tag "noty" %>
<%= javascript_include_tag "noty" %>

【讨论】:

    猜你喜欢
    • 2020-04-03
    • 2018-09-22
    • 2021-01-23
    • 2020-05-09
    • 1970-01-01
    • 2020-05-10
    • 2018-03-31
    • 2019-07-01
    • 1970-01-01
    相关资源
    最近更新 更多