简体   繁体   English

如何使用JavaScript中的define导入模块的子模块?

[英]How to import sub-modules of a module using define in JavaScript?

I'm new to AMD and trying to use react-context-menu library. 我是AMD的新手,正在尝试使用react-context-menu库。 The docs for the library imports modules like , 该库的docs导入模块,例如

    import { ContextMenu, MenuItem, ContextMenuTrigger } from "react-contextmenu";

Now if I were to include the module using define[] , how would I do it ? 现在,如果要使用define[]包含模块,我该怎么做?

eg for including react I would do, eg为了包括我会做的反应,

    define(["react"], function(React){

    });

What should I do if I also want to include react-context-menu and use it's submodules ContextMenu, MenuItem, ContextMenuTrigger ? 如果我还想包含react-context-menu并使用它的子模块ContextMenu, MenuItem, ContextMenuTrigger怎么办?

    define(["react", "react-context-menu"], function(React, ??????){

    });

Thanks in advance. 提前致谢。

也许你应该考虑使用CommonJS的模块var $ = require('jquery')与捆绑,而不是一个模块,无论是一起的WebPackbrowserify

    define(["react-contextmenu"], function(ReactContextMenu){

       var ContextMenu = ReactContextMenu.ContextMenu;
       var ContextMenuTrigger = ReactContextMenu.ContextMenuTrigger;
       var MenuItem = ReactContextMenu.MenuItem;

    });

The sub-modules can be included using . 可以使用来包含子模块. (dot). (点)。 <module>.<sub-module> worked for me. <module>.<sub-module>为我工作。

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

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