在requirejs中,我们可以通过以下方式设置js的名称:
requirejs.config({
paths: {
'jquery': '//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js'
}
});
并将其与此一起使用:
requirejs(['jquery'],function ($) {
//loaded and can be used here now.
});
但对于像 fileuploads 这样的插件来说,需要大量的 js 文件。他们的文档展示了如何将其与 requirejs 一起使用:https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-use-jQuery-File-Upload-with-RequireJS https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-use-jQuery-File-Upload-with-RequireJS
但是,我怎样才能将它们全部归为一个名字呢?
requirejs(['jquery','fileupload'],function ($) {
//all fileupload js has been loaded and ready to use
});
这样当我需要fileupload时,它就会加载所有需要的js,而不需要一一要求。
谢谢。
您可以创建一个元模块来导入所有必要的资源并将它们捆绑在一起,然后最终模块成为隐式加载的传递依赖项:
文件上传.js
define(['jquery',
'js/jquery.iframe-transport',
'js/jquery.fileupload-ui'
], function () {
// all needed dependencies loaded
});
当你需要时fileupload
您确保所有需要的依赖项都存在。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)