我正在我的多页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);