这是我已经工作了一段时间的代码。由于某种原因,它向我返回以下错误:
Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned.
这甚至在我尝试使用更新插入插件之前就发生了。
db.get(id).then(doc => {
console.log(doc);
return db.upsert(id, doc => {
doc.exp_date = moment(doc.exp_date).add(parseInt(document.getElementById('ext_date').value), 'years');
return doc;
}).then(res => console.log(res)).catch(err => console.log(err));
})
我可以知道此错误的解决方案吗?
无法克隆 Moment 实例。尝试:
postMessage(moment(0), '*'); // also throws DataCloneError DOMException
克隆逻辑不允许复制函数,情况可能是这样。儗:
postMessage({f: function(){}}); // also throws DataCloneError
并检查:
typeof moment(0)._locale.ordinal; // "function"
您需要将 add()
返回的对象转换为可以克隆的对象,例如日期、数字等。