From 648a2683d29dee66320abf801b444f3062a56ff0 Mon Sep 17 00:00:00 2001 From: 622aa39c1f9b166ab1a38c05 <622aa39c1f9b166ab1a38c05@devide> Date: Thu, 6 Jul 2023 08:43:00 +0000 Subject: [PATCH] Thu Jul 6 08:43:00 UTC 2023 inscode --- src/App.vue | 4 ++-- src/js/storage.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index dd15e5d..60bcc06 100644 --- a/src/App.vue +++ b/src/App.vue @@ -414,9 +414,9 @@ export default { for (let id = start; id < end; id++) { tmpHistory.push(this.message[id]) } - StorageApi.set(this.history.name, cacheKey, JSON.stringify(tmpHistory)) + StorageApi.put(this.history.name, cacheKey, JSON.stringify(tmpHistory)) } else { - StorageApi.set(this.history.name, cacheKey, JSON.stringify(this.message)) + StorageApi.put(this.history.name, cacheKey, JSON.stringify(this.message)) } }, diff --git a/src/js/storage.js b/src/js/storage.js index 0973562..9c81ffb 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -49,6 +49,25 @@ export default { } }) }, + put(tableName = defaultTableName, key, val, id = 100){ + let request = db.transaction(tableName, 'readwrite') + .objectStore(tableName) + .put({ + id: id, + key: key, + data: val + }) + return new Promise((resolve, reject) => { + request.onsuccess = (event) => { + console.info('添加成功', event) + resolve(event) + } + request.onerror = (event) => { + console.info('添加失败') + reject(event) + } + }) + }, getAll(tableName = defaultTableName){ let request = db.transaction(tableName, 'readwrite') .objectStore(tableName) -- GitLab