无法将 <Script/> 标签附加到 <div> index.html react.js

问题描述

嗨,我需要将下面的脚本附加到 react 的 index.html 中的 div 标签。我从后端 API 端获取此脚本

<style type='text/css'>
       .helpButton .uiButton {
        background-color: #005290;
        font-family: "Arial",sans-serif;
      }
    
       .helpButton .uiButton:focus {
        outline: 1px solid #005290;
      }
    </style>
    
    <script type='text/javascript' src='.min.js'></script>
    <script type='text/javascript'>
      var initESW = async function (gslbBaseURL) {
        embedded_svc.settings.samplesplayHelpButton = true; 
        embedded_svc.settings.language = ''; 
        
        
        embedded_svc.settings.enabledFeatures = ['LiveAgent'];
        embedded_svc.settings.entryFeature = 'LiveAgent';

        try {

          await embedded_svc.init(
            'https://test--sample.my.salesforce.com','https://sample-test.cs81.force.com/Surveys',gslbBaseURL,'111111111','DDC_test',{
              baseLiveAgentContentURL: 'https://test.salesforceliveagent.com/content',deploymentId: '111111111',buttonId: '111111111',baseLiveAgentURL: 'https://test.salesforceliveagent.com/chat',eswLiveAgentDevName: 'test_event',isOfflinesupportEnabled: true
            }
          );
        }
        catch (error) {
          console.log(error)
        }
      };

      if (!window.embedded_svc) {
        var s = document.createElement('script');
        s.setAttribute('src','https://test--sample.my.salesforce.com/embeddedservice/5.0/esw.min.js');
        s.onload = function () {
          initESW(null);
        };
        document.body.appendChild(s);
      } else {
        initESW('https://service.force.com');
      }
    </script>

我可以将上述脚本附加到 index.html react 的 div 标签但它不会在 UI 上呈现。 我写了下面的代码将数据附加到 index.html

var data = API call;
document.getElementById('webchat').innerHTML = data;

我的 index.html 有 ID 为“webchat”的 div 标签

<div id="webchat"></div>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)