Browse Source

indexedDB总结

master
aBin 4 years ago
parent
commit
df22d739c2
  1. 5
      package-lock.json
  2. 1
      package.json
  3. 4
      src/main.js
  4. 4
      src/router/index.js
  5. 49
      src/views/Index/Index.vue
  6. 27
      src/views/Index/Index1.vue

5
package-lock.json

@ -4684,6 +4684,11 @@
"assert-plus": "^1.0.0"
}
},
"dayjs": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.6.tgz",
"integrity": "sha512-AztC/IOW4L1Q41A86phW5Thhcrco3xuAA+YX/BLpLWWjRcTj5TOt/QImBLmCKlrF7u7k47arTnOyL6GnbG8Hvw=="
},
"de-indent": {
"version": "1.0.2",
"resolved": "https://registry.npm.taobao.org/de-indent/download/de-indent-1.0.2.tgz",

1
package.json

@ -11,6 +11,7 @@
"ant-design-vue": "^1.2.4",
"compression-webpack-plugin": "^6.1.1",
"core-js": "^3.6.5",
"dayjs": "^1.10.6",
"echarts": "^4.9.0",
"echarts-gl": "^1.1.1",
"js-md5": "^0.7.3",

4
src/main.js

@ -3,7 +3,7 @@
* @email: binbin0314@126.com
* @Date: 2021-07-09 09:10:13
* @LastEditors: aBin
* @LastEditTime: 2021-07-09 10:10:58
* @LastEditTime: 2021-07-12 10:49:37
*/
// @ts-ignore
import Vue from 'vue';
@ -15,11 +15,13 @@ import store from './store';
import './plugins/ant-design-vue.js';
import 'common/portrait.styl';
import md5 from 'js-md5';
import * as dayjs from 'dayjs';
// import './assets/icon/iconfont.css';
// import VueDOMPurifyHTML from 'vue-dompurify-html';
// import moment from 'moment'; //导入文件
// Vue.prototype.$moment = moment; //赋值使用
Vue.prototype.$md5 = md5;
Vue.prototype.$dayjs = dayjs;
Vue.config.productionTip = false;
window.vm = new Vue({

4
src/router/index.js

@ -3,11 +3,11 @@
* @email: binbin0314@126.com
* @Date: 2021-06-05 12:16:54
* @LastEditors: aBin
* @LastEditTime: 2021-07-09 09:11:07
* @LastEditTime: 2021-07-12 10:38:20
*/
import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from 'views/Index/Index.vue';
import Home from 'views/Index/Index1.vue';
Vue.use(VueRouter);

49
src/views/Index/Index.vue

@ -3,7 +3,7 @@
* @email: binbin0314@126.com
* @Date: 2021-07-09 09:10:14
* @LastEditors: aBin
* @LastEditTime: 2021-07-09 19:01:32
* @LastEditTime: 2021-07-12 15:33:35
-->
<template>
<div style="padding: 12px">
@ -60,6 +60,7 @@ export default {
console.log('error', error);
}
},
// indexedDB
justifyIndexDEB() {
if ('indexedDB' in window) {
//
@ -71,52 +72,35 @@ export default {
window.indexedDB = window.mozIndexedDB || window.webkitIndexedDB;
}
},
//
createindexDB() {
const that = this;
//1-dbInfo dbNamedbVersion
var dbInfo = {
dbName: 'DataBase',
dbVersion: 2021,
dbInstance: {},
};
//2- indexedDB.open
//2- indexedDB.open
//
var openRequest = window.indexedDB.open(dbInfo.dbName, dbInfo.dbVersion);
//3-upgradeneededsuccessonerror
openRequest.onupgradeneeded = function(e) {
// ^-*
console.log('第一次打开该数据库,或者数据库版本发生变化....', new Date().getTime());
that.db = e.target.result;
var storeNames = that.db.objectStoreNames;
//
if (!storeNames.contains('chart')) {
that.db.createObjectStore('chart', { keyPath: 'kkk' });
}
};
openRequest.onsuccess = function(e) {
//success^-^
console.log('数据库打开成功...', new Date().getTime());
that.db = e.target.result;
var trans = that.db.transaction(['chart'], 'readwrite');
var store = trans.objectStore('chart');
//4-.....wu la wu la.....
// that.addData(); // ------->xian
// del_data(db); //
// deal_data(db); //
// traverse_data(db); //
// that.read();
// that.update_data(); //Add
};
openRequest.onerror = function(e) {
//error*-*
console.log('数据库打开失败...');
@ -202,6 +186,29 @@ export default {
var request = store.put(obj);
console.log('已更新数据', new Date().getTime());
},
remove_data() {
//1-
//2-,indexDB readwrite readonly
var trans = this.db.transaction(['chart'], 'readwrite');
var store = trans.objectStore('chart');
// 3-
var request = store.delete(1);
request.onsuccess = function(event) {
console.log('数据删除成功');
};
},
readAll() {
var trans = this.db.transaction(['chart'], 'readwrite');
var store = trans.objectStore('chart');
store.openCursor().onsuccess = function(event) {
if (event.target.result) {
console.log(event.target.result);
} else {
console.log('没有更多数据了!');
}
};
},
},
};
</script>

27
src/views/Index/Index1.vue

@ -0,0 +1,27 @@
<!--
* @Author: aBin
* @email: binbin0314@126.com
* @Date: 2021-07-12 10:36:28
* @LastEditors: aBin
* @LastEditTime: 2021-07-12 10:50:04
-->
<template>
<div>123</div>
</template>
<script>
export default {
name: 'Index1',
data() {
return { time: null };
},
created() {
this.getTime();
},
methods: {
getTime() {
const time = this.$dayjs().format();
console.log(time); // 2021-07-12T10:49:59+08:00
},
},
};
</script>
Loading…
Cancel
Save