繁体   English   中英

Require.js和Imager.js未定义函数

[英]Require.js and Imager.js undefined function

我在将Imager.js库添加到require.js加载时遇到问题,该脚本在没有require.js的情况下运行完美

Main.js

define([
        'jquery',
        'bootstrap',
        'imager',
        'video'
    ],
    function($) {
        'use strict';
        $('.dropdown-toggle').dropdown();
        $('#bvideo').magnificPopup({
            type: 'inline'
        });
        videojs('video-cdve', {
            'controls': true,
            'autoplay': false,
            'preload': 'auto',
            'width': 'auto',
            'height': 'auto'
        });
        new Imager({
            availableWidths: {
                320: '320x240',
                640: 'large',
                1024: 'large_x2',
            }
        });
    });

我收到此错误

未捕获的ReferenceError:未定义成像器

当我定义热像仪时

define([
        'jquery',
        'bootstrap',
        'imager',
        'video'
    ],
    function($, Imager) {
        'use strict';
        $('.dropdown-toggle').dropdown();
        $('#bvideo').magnificPopup({
            type: 'inline'
        });
        videojs('video-cdve', {
            'controls': true,
            'autoplay': false,
            'preload': 'auto',
            'width': 'auto',
            'height': 'auto'
        });
        new Imager({
            availableWidths: {
                320: '320x240',
                640: 'large',
                1024: 'large_x2',
            }
        });
    });

现在我收到这个错误

未捕获的TypeError:undefined不是函数

发生了什么? 我如何用require正确添加该库?

您的参数以与您在需求中列出它们的顺序相同的顺序绑定到模块,因此在执行此操作时:

define([
        'jquery',
        'bootstrap',
        'imager',
        'video'
    ],
    function($, Imager) {

您将Imager绑定到'bootstrap'模块的值。 更改顺序:

define([
        'jquery',
        'imager',
        'bootstrap',
        'video'
    ],
    function($, Imager) {

我也考虑过是否需要Imager的填充程序,但是我在他们的代码中看到他们检测到AMD环境并调用define

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM