美文网首页
react 中 加入script标签

react 中 加入script标签

作者: Fairy_zhao | 来源:发表于2019-11-29 23:48 被阅读0次
componentDidMount () {
    const script = document.createElement("script");

    script.src = "https://use.typekit.net/foobar.js";
    script.async = true;

    document.body.appendChild(script);
}
//加入 点击栏目滑动到相应位置
      const script = document.createElement("script")
      script.text = `
        function scrollToAnchor (anchor, options) {
          if (anchor) {
            try {
              var el = document.getElementById(anchor)
              if (el) el.scrollIntoView(options)
            } catch (err) {
            }
          }
        }

        function maoScroll(anchor){
            scrollToAnchor(anchor.replace(/#/g, ''), { block: 'start', behavior: 'smooth', })
        }
      `
      document.body.appendChild(script)

相关文章

网友评论

      本文标题:react 中 加入script标签

      本文链接:https://www.haomeiwen.com/subject/ffvjuctx.html