【问题标题】:import jQuery plugin in Js Files在 Js 文件中导入 jQuery 插件
【发布时间】:2018-05-18 11:33:59
【问题描述】:

我想知道从 npm 安装后如何导入 jQuery 库。 我做了以下,但我遇到了以下错误。

import countdown from 'jquery.countdown';
$.countdown = countdown;

$("#hours1").countdown("2020/05/01 16:00:00", function (event) {
    $(this).text(event.strftime('%H'));
});

import countdown from 'jquery.countdown';
window.$.countdown = countdown;

$("#hours1").countdown("2020/05/01 16:00:00", function (event) {
    $(this).text(event.strftime('%H'));
});

错误:

Uncaught TypeError: $(...).countdown is not a function

【问题讨论】:

    标签: javascript jquery npm ecmascript-6


    【解决方案1】:

    尝试从node_modules 文件夹导入脚本:

    import 'jquery-countdown/dist/jquery.countdown.min.js';
    

    【讨论】:

    • 对不起,没有你提到的路径。
    【解决方案2】:

    我认为官方 NPM 页面上存在错误。 https://www.npmjs.com/package/jquery-countdown

    尝试像这样通过 NPM 安装:

    npm install --save jquery-countdown
    

    然后使用

    import 'jquery-countdown/dist/jquery.countdown.min';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 2022-06-10
      • 2020-07-02
      • 2021-03-02
      • 2016-08-17
      • 2020-05-06
      相关资源
      最近更新 更多