Reactjs 有没有一种从IndexedDB读取blob的简单方法?

Reactjs 有没有一种从IndexedDB读取blob的简单方法?,reactjs,indexeddb,Reactjs,Indexeddb,我已经将Blob图像写入IndexedDB,如下所示。 但我不知道,如何读出来,并显示在网页上。 我试过下面的方法,但失败了 let transaction = db.transaction(["elephants"], 'readwrite') let reqGetRes = transaction.objectStore("elephants").get(1) reqGetRes.onsuccess = function (event) { let

我已经将Blob图像写入IndexedDB,如下所示。 但我不知道,如何读出来,并显示在网页上。 我试过下面的方法,但失败了

let transaction = db.transaction(["elephants"], 'readwrite')
let reqGetRes = transaction.objectStore("elephants").get(1)
reqGetRes.onsuccess = function (event) {
  let imgFile = reqGetRes.result 
  let URL = window.URL || window.webkitURL;
  let imgURL = URL.createObjectURL(imgFile);
  return imgURL
}
但是,当我通过const imgSrcFrmIdb=getImgFromIdb()调用上述代码时

这张照片无论如何都不显示

网页显示:


请包含函数
getImgFromIdb()
中的代码,并清楚描述此函数的返回值。这将帮助你得到一个更好的答案。谢谢我敢打赌他们没有把它当作异步调用来正确处理。我也会给getImgFromIdb打电话。