我有一个在我的网站上编辑个人资料的功能,其中我必须更改个人资料图片。它会发生变化,但在页面刷新时,会恢复到旧的个人资料图片。为了解决这个问题,我尝试将它存储在localforage中。问题是,它不会存储在localforage中,并且在刷新时,图片会恢复为旧图片。如何在localforage中正确地存储图像(或其URL,视情况而定)?
我试着这样存储它:
const { profilePic } = this.props;
localforage.getItem('currentUser').then((currentUser) => {
currentUser.profile_pic.url = profilePic;
localforage.setItem('currentUser',currentUser);
});其中currentUser如下所示:

我希望新上传的图像保存在localforage中。现在,它没有被正确地存储在localforage中。
发布于 2019-05-07 20:14:07
请尝试
const { profilePic } = this.props;
localforage.getItem('currentUser').then((currentUser) => {
currentUser.profile_pic.url = profilePic;
localforage.setItem('currentUser',currentUser).then(()=>{});
});我试过了
localforage.getItem('somekey').then((value) => {
// This code runs once the value has been loaded
// from the offline store.
localforage.setItem('somekey', 'some other value').then(()=>{
})
}).catch(function(err) {
// This code runs if there were any errors
console.log(err);
});
localforage.getItem('somekey').then(function(value) {
// This code runs once the value has been loaded
// from the offline store.
console.log(value);
}).catch(function(err) {
// This code runs if there were any errors
console.log(err);
});这对我很有效。:-)
https://stackoverflow.com/questions/56021316
复制相似问题