Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript脚本index.html公用文件夹中的read类_Javascript_Reactjs - Fatal编程技术网

javascript脚本index.html公用文件夹中的read类

javascript脚本index.html公用文件夹中的read类,javascript,reactjs,Javascript,Reactjs,我需要知道如何将index.html公用文件夹文件中的javscript脚本嵌入react组件。我已经在使用这个方法,但是类仍然没有定义 componentDidMount () { this._loadScript('/library/es6-shim.js', false) this._loadScript('/library/fingerprint.sdk.min.js', true) this._loadScript('/library/websdk.client

我需要知道如何将index.html公用文件夹文件中的javscript脚本嵌入react组件。我已经在使用这个方法,但是类仍然没有定义

componentDidMount () {
    this._loadScript('/library/es6-shim.js', false)
    this._loadScript('/library/fingerprint.sdk.min.js', true)
    this._loadScript('/library/websdk.client.bundle.min.js', false)
    var script = document.createElement('script')
    script.async = true
    script.innerHTML = "this.sdk = new Fingerprint.WebApi;"
    document.head.appendChild(script)
  }

  _loadScript = (src, type) => {
    var tag = document.createElement('script');
    tag.async = true;
    tag.src = src;
    document.head.appendChild(tag)
    // tag.onload = () => this.scriptLoaded()

    console.log('headers', document.head)
  }

我需要在我的组件中读取新的Fingerprint.WebApi实例。

您应该加载所有三个库,然后您应该可以访问全局公开的
Fingerprint

componentDidMount() {
  Promise.all([
      this._loadScript('/library/es6-shim.js'),
      this._loadScript('/library/fingerprint.sdk.min.js'),
      this._loadScript('/library/websdk.client.bundle.min.js')
  ])).then(() => {
    // Fingerprint should be available on the window.
    console.log(window.Fingerprint);
    const sdk = new window.Fingerprint.WebApi();
  });
}
_loadScript = (src) => {
  return new Promise((resolve, reject) => {
    const script = document.createElement('script');
    script.setAttribute('type', 'text/javascript');
    script.setAttribute('async', 'true');
    script.setAttribute('src', url);
    script.onload = resolve;
    script.onerror = reject;
    document.head.appendChild(script);
  });
}

你为什么要注释掉
标记.onload
回调?我想你可以使用他们的npm包并遵循GitHub的用法示例。已经在使用
标记.onload
但仍然无法读取该类/instancehi@awran5,我认为指纹JS2不适用于生物特征指纹,而是适用于指纹浏览器。请更新您的示例,说明如何使用
标记。onload
?谢谢。。。。现在一切都好了,在我错了自由之路之前,