使用 'noty'Rails 5 中的 js 库 [英] Use 'noty' js library in Rails 5

查看:55
本文介绍了使用 'noty'Rails 5 中的 js 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作 noty.js ( https://ned.im/noty/#/安装- 一个用于通知的库)在我的 Rails 应用中工作.

I am trying to make noty.js ( https://ned.im/noty/#/installation - a library for notifications) work into my Rails app.

我已经用 npm 安装了它

I have installed it with npm

 npm install noty

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

Now, it appears under node_modules. When I try to test it in a js file with

new Noty({

    text: 'Some notification text'

}).show();

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

I will get ' Uncaught ReferenceError: Noty is not defined' If I try to import it in my js file : import Noty from 'noty' ; I will get 'Uncaught SyntaxError: Unexpected identifier' ( my 'noty' path is visible- I can be directed to it).

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

How can I properly make it work?

推荐答案

如果您不使用 webpack 或其他一些 JS 资产管理系统,则使用 NPM 安装将不起作用.你需要

If you're not using webpack or some other JS asset management system, installing with NPM won't work. You'll need to

  1. 下载noty.cssnoty.js,放在各自的assets目录下
  2. 将它们添加到您的 assets.rb
  3. 重启你的服务器
  4. application.js 之前引用布局中的文件
  1. Download noty.css and noty.js, place them in their respective assets directory
  2. Add them to your assets.rb
  3. Restart your server
  4. Reference the file in your layout prior to your application.js

阅读有关资产管道 了解更多详情.

Read the guides on the Asset Pipeline for more details.

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

这篇关于使用 &amp;#39;noty&amp;#39;Rails 5 中的 js 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆