如何将 uploadcare 导入 react.js 项目?
How can I import uploadcare into a react.js project?
如何将 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
我收到上面这条棕色警告消息的事实(我同意,因为我希望设置
public 键直接通过 javascript API) 让我认为 uploadcare.js 文件有
已正确包含,但 uploadCareMin2 错误让我觉得我没有正确导入它。
TL;DR;如何将 uploadcare Javascript API 导入到 react.js 项目中?
感谢您的帮助。
不确定 uploadcare
是什么,但尝试
import '../lib/uploadcare.min.js'
看起来您正在直接导入文件,这意味着您必须希望作者将文件导出为 export default
才能按照您显示的方式导入它。他们很可能只是将其粘贴在全局 space 中。
如果不是,也有可能他们导出了命名值,所以请尝试:
import { uploadcare } from '../lib/uploadcare.min.js';
您现在还可以按照 uploadcare's website 上的说明使用 npm install:
NPM
npm install uploadcare-widget
ES6 usage way:
import uploadcare from 'uploadcare-widget';
CommonJS usage way:
var uploadcare = require('uploadcare-widget);
如何将 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
我收到上面这条棕色警告消息的事实(我同意,因为我希望设置 public 键直接通过 javascript API) 让我认为 uploadcare.js 文件有 已正确包含,但 uploadCareMin2 错误让我觉得我没有正确导入它。
TL;DR;如何将 uploadcare Javascript API 导入到 react.js 项目中?
感谢您的帮助。
不确定 uploadcare
是什么,但尝试
import '../lib/uploadcare.min.js'
看起来您正在直接导入文件,这意味着您必须希望作者将文件导出为 export default
才能按照您显示的方式导入它。他们很可能只是将其粘贴在全局 space 中。
如果不是,也有可能他们导出了命名值,所以请尝试:
import { uploadcare } from '../lib/uploadcare.min.js';
您现在还可以按照 uploadcare's website 上的说明使用 npm install:
NPM
npm install uploadcare-widget
ES6 usage way:
import uploadcare from 'uploadcare-widget';
CommonJS usage way:
var uploadcare = require('uploadcare-widget);