美文网首页
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标签

  • 2 - 搭建 React 开发环境

    1. script 标签引入方式 react.js - React 的核心库 react-dom.js - 提供与...

  • 常用API

    React React 是 React 库的顶层 API,可以使用以下几个方式引入 使用 script 标签引入的...

  • 20-01-28JS基础语法1

    字面量,常量,变量 1. 在 标签中加入typ...

  • 2018-01-15

    标签 代码块 2....

  • 文本框输入文字时动态变化

    在script标签中

  • JavaScript

    1.JavaScript script标签script标签可以放在html中的任何地方,一般建议放在head标签中...

  • electron--html文件导入js的方法

    1、script标签中,通过src的方式导入 2、script标签中,通过require的方式导入 require...

  • web前端开发过程中如何写JavaScript程序?

    script标签使用 < script >< /script > src : 外联script 标签(立即调用,不...

网友评论

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

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