如何跨模块使用脚本库

时间:2016-08-29 15:18:58

标签: javascript reactjs

我正在尝试在我正在使用的反应项目中使用第三方库“emailjs.com”(使用webpack捆绑模块)。

我遇到的问题是我需要在html中初始化库,如此

<script type="text/javascript" src="https://cdn.emailjs.com/dist/email.min.js"></script>
<script type="text/javascript">
   (function(){
      emailjs.init("YOUR USER ID");
   })();
</script>

https://www.emailjs.com/docs/api-reference/emailjs-send/

现在我需要点击按钮

在我的react组件中调用库
  _submitForm(e) {

    e.preventDefault();
    alert("Button Click works"); // This is printed fine

    // Undefined
    emailjs.send("my_service","my_template",{
      name: "James",
      notes: "Check this out!"
    });
  }

但是我收到一封emailJS是未定义的错误(正如我所料)。我的问题是给出emailJS模块的“表单”组件范围的正确方法。

我尝试过创建“emailjs.js”

export default () => {
   // Minified email code in here
}

然后像这样导入

import emailjs from '../PathToComponent/emailjs'; 

然而,这是无法编译,我收到错误“找不到模块:错误:无法解析模块'vertx'”,但所有依赖项应该包含在emailJS缩小文件中?

如果有人有任何建议或者更好的方法从反应组件中发送我的电子邮件,请告诉我们!

表单组件:http://pastebin.com/x5KVPKXm emailJS导出:http://pastebin.com/NA40ZrTT

0 个答案:

没有答案