我正在尝试为我的 reactjs 应用程序使用uploadcare来存储图像。但我无法让它发挥作用。我已按照文档进行操作,但收到错误消息“未捕获的 TypeError:无法读取 Object.u.openDialog (uploadcare.min.js:24) 处未定义的属性 'tabs'”。虽然我已经 npm 安装了 uploadcare-widget 并将其导入到我的文件中,但它不起作用。以下是相关代码:
首先,我在 index.html 中添加脚本标记,如下所示:
<script>
UPLOADCARE_PUBLIC_KEY = "demopublickey";
</script>
然后在我的组件中我这样做:
import uploadcare from 'uploadcare-widget';
class ImageComponent extends React.Component {
componentDidMount() {
uploadcare.start({publicKey: 'demopublickey'})
}
addImage(e) {
uploadcare.openDialog(null, {
imagesOnly: true,
multiple: false,
}).done((file) => {
file.promise().done((fileInfo) => {
console.log(fileInfo.cdn)
})
})
}
render () {
const imageInput = (
<div className='image-box'>
<Button onClick={this.addImage}>Add Image</Button>
</div>
)
return (
<div>
{ this.state.imgSrc && this.renderImageView() }
{ !this.state.imgSrc && imageInput }
</div>
)
}
}
我已经坚持了很长时间了。请帮忙!