export default {
indexedDB: window.indexedDB || window.webkitindexedDB || window.msIndexedDB,
openDb(dbName, version = 1, db, newStore, cb) {
const request = this.indexedDB.open(dbName, version);
request.onerror = function(e) {
console.error("打开数据库错误", e);
};
request.onsuccess = function(e) {
console.log("打开数据库成功", e);
db = e.target.result;
if (cb) cb(db);
};
// 建表
request.onupgradeneeded = function(e) {
var mdb = e.target.result;
console.log(mdb);
if (!mdb.objectStoreNames.contains(newStore.name)) {
const objStore = mdb.createObjectStore(newStore.name, {
// keyPath: newStore.key
autoIncrement: true
});
const tableMap = {
name: "",
amount: 0,
platform: "",
num: 0,
money: 0,
date: "",
method: 0
};
Object.keys(tableMap).forEach(key =>
objStore.createIndex(key, k
来源:CSDN
作者:guo_1991
链接:https://blog.csdn.net/guo_1991/article/details/103988955