【发布时间】:2018-05-21 19:12:56
【问题描述】:
我正在使用 Noty 版本 3 https://github.com/needim/noty。根据文档,我应该使用 require 或 import。
import Noty from 'noty';
new Noty({
text: 'Notification text'
}).show();
// or
const Noty = require('noty');
new Noty({
text: 'Notification text'
}).show();
但没有一个有效。即使在 Chrome 的最新版本中也是如此。
当我使用 require 时:
Uncaught ReferenceError: require is not defined
导入时:
Uncaught SyntaxError: Unexpected token import
【问题讨论】:
-
你是在node里运行的吗?
-
你为什么不使用
script标签来包含它? -
require 是服务器端 nodeJS 的一部分。对于浏览器代码,您需要通过
<script>标签包含库。两种不同的操作环境。
标签: javascript noty