如何在ReactJS中集成外部Javascript

时间:2019-05-28 14:34:45

标签: javascript reactjs

我正在我的多页ReactJS应用程序中设置TOPOL.io电子邮件生成器。我如何将其集成到我的ReactJS应用程序中,并使用它们的函数来调用RestAPI端点。

const pluginOption = document.createElement("script");

  pluginOption.textContent = `var TOPOL_OPTIONS = {
      id: "#app",
      authorize: {
        apiKey: "apikey",
        userId: "userID"
      },
      templateId: 1,
      removeTopBar: true,
      callbacks: {
        onSaveAndClose: function(json, html) {
          // HTML of the email
          console.log(html);
          // JSON object of the email
          console.log(json); 
          // Implement your own close callback
          // Data variable contains the response data of the save request
        },
        onSave: function(json, html) {
            var encodedeString = window.btoa(JSON.stringify(json));
          // HTML of the email
          console.log(encodedeString);

    const URL = URL;

    var params = {
        api: "http://192.168.1.192/saveemail",
      };
    let http = new XMLHttpRequest();
    http.open('POST', URL,true);
    http.setRequestHeader('Content-Type', 'application/json');
     http.send(JSON.stringify(params));
    console.log(http);
    return http;

          // JSON object of the email
          console.log(window.atob(encodedeString));
        }
      }
    };`;

然后是插件脚本,然后是类似的

document.body.appendChild(pluginScript);

0 个答案:

没有答案