我正在嘗試使用uploadcare來爲我的reactjs應用程序存儲圖像。但我無法使其工作。我已經按照文檔,但我得到一個錯誤「Uncaught TypeError:無法讀取Object.u.openDialog(uploadcare.min.js:24)未定義的屬性'選項卡'」。雖然我有npm安裝uploadcare-widget並將其導入到我的文件中,但它不起作用。下面是相關代碼:uploadcare在reactjs應用程序中未定義
首先我添加腳本標籤中的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>
)
}
}
我現在已經停留很長時間了。請幫忙!
似乎是你想要的:https://github.com/uploadcare/uploadcare-widget-react-demo – pirs