我在Vue + Laravel应用程序中添加了一个indexedDB,下面是我目前使用的代码:
export default {
mixins: [VueGoogleMap.MapElementMixin],
created() {
this.eventBus.$on("refresh-map", () => {
this.fetchHexagons();
});
const getAllBuildings = () => Vue.http.get("/sandbox/buildings");
getAllBuildings().then((result) => {
const async = Dexie.async;
const spawn = Dexie.spawn;
const db = new Dexie("buildings");
db.version(1).stores({
buildings: `++dexie_id, id, name, address, city, nr_units, lat, long, purchased`,
});
db.transaction("rw", db.buildings, function* () {
result.body.forEach(function*(el) {
const a = yield db.buildings.add({
id: el.id,
name: el.name,
address: el.address,
city: el.city,
nr_units: el.nr_units,
lat: el.lat,
long: el.long,
purchased: el.purchased,
});
});
console.log("done");
}).catch(function(err) {
// Catch any error event or exception and log it:
console.error(err.stack || err);
});如您所见,我正在查询DB,以便传输indexedDB中的所有建筑物,以便更快地解析它们(我需要在地图中显示它们.)。问题是,当我运行这段代码时,我会得到以下错误:
CanvasOverlay.vue?e208:68 Error: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
at Transaction.create (dexie.es.js?f8d5:2900)
at eval (dexie.es.js?f8d5:2222)
at eval (dexie.es.js?f8d5:1343)
at callListener (dexie.es.js?f8d5:1026)
at endMicroTickScope (dexie.es.js?f8d5:1113)
at IDBOpenDBRequest.eval (dexie.es.js?f8d5:1180)我安装的唯一软件包是Dexie:
npm install --save dexie我需要安装更多的东西,还是可能是Webpack的问题?
发布于 2017-10-26 09:23:13
尝试删除数据库并重新运行代码。根据这些医生,这个问题很常见,当同一个版本(1)被更新而不增加版本号时就会发生。
另外,我还看到了另一个错误--您不能使用forEach()调用中的函数*。相反,请使用:
for (let el of result.body) {
...
}甚至更好:
const itemsToAdd = result.body.map(el => ({
id: el.id,
name: el.name,
address: el.address,
city: el.city,
nr_units: el.nr_units,
lat: el.lat,
long: el.long,
purchased: el.purchased,
}));
return db.buildings.bulkAdd(itemsToAdd);https://stackoverflow.com/questions/46949822
复制相似问题