如何将uploadcare导入react.js项目?

时间:2016-04-13 21:31:59

标签: javascript reactjs uploadcare

如何将uploadcare导入react.js项目?

我的导入部分看起来像这样

    // main imports
    import React from 'react';
    import {render} from 'react-dom';
    import { Router, Route, hashHistory } from 'react-router'
    import jQuery from '../scripts/jquery-1.8.3.min.js'
    import uploadcare from '../lib/uploadcare.min.js'

然后我想像这样使用uploadcare(通过javascript API):

onAddPhotosClick: function() {
    console.log("++ add photos");
    uploadcare.openDialog(null, {
        publicKey: "xxxxxxxxxxxx",
        imagesOnly: true,
        tabs: "file url facebook gdrive dropbox instagram evernote flickr skydrive"
    });
},

我的代码到达openDialog行,然后抛出此错误:

:8081/static/react_build/bundle.js:86 Uncaught TypeError: _uploadcareMin2.default.openDialog is not a function

之前,在页面加载期间,我的控制台记录:

Global public key not set. Uploads may not work!
Add this to the <head> tag to set your key:

<script>
UPLOADCARE_PUBLIC_KEY = 'your_public_key';
</script>
:8081/static/react_build/bundle.js:85 ++ add photos

我上面得到这个棕色警告信息的事实(我很好,因为我希望设置 公钥直接通过javascript API)让我觉得uploadcare.js文件有 已正确包含,但uploadCareMin2错误让我觉得我没有正确导入它。

TL; DR;如何将uploadcare Javascript API导入react.js项目?

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

不确定uploadcare是什么,但请尝试

import '../lib/uploadcare.min.js'

您似乎直接导入文件意味着您必须希望作者将文件导出为export default,以便按照您展示的方式导入文件。他们很可能只是把它放在全球空间。

如果没有,它们也可能导出一个命名值,所以请尝试:

import { uploadcare } from '../lib/uploadcare.min.js';

答案 1 :(得分:0)

您现在也可以使用uploadcare's website中记录的npm install:

.as-console-wrapper { max-height: 100% !important; top: 0; }
相关问题