📜  react 中的外部脚本 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:10.835000             🧑  作者: Mango

代码示例1
componentDidMount() {
    const script = document.createElement("script");
    script.async = true;
    script.src = "https://some-scripturl.js";
    script.onload = () => this.scriptLoaded();



    //For head
    document.head.appendChild(script);

    // For body
    document.body.appendChild(script);

    // For component
    this.div.appendChild(script);

  }