Commit 224a23d7 by jack

优化数据

1 parent 31b3b0ba
const getters = {
// 获取车型数据
getTreeData:state => {
let arr = state.vehicleTree;
let n = localStorage.getItem('carTree') ? JSON.parse(localStorage.getItem('carTree')) : []
return arr || n;
}
}
export default getters;
\ No newline at end of file \ No newline at end of file
...@@ -2,11 +2,13 @@ import Vue from 'vue'; ...@@ -2,11 +2,13 @@ import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import state from './state'; import state from './state';
import mutations from './mutations'; import mutations from './mutations';
import getters from './getter'
Vue.use(Vuex); Vue.use(Vuex);
const store = new Vuex.Store({ const store = new Vuex.Store({
state, state,
getters,
mutations mutations
}) })
......
...@@ -2,5 +2,10 @@ export default { ...@@ -2,5 +2,10 @@ export default {
//更新全局baseURL //更新全局baseURL
updateBaseURL(state, newBaseURL) { updateBaseURL(state, newBaseURL) {
state.baseURL = newBaseURL; state.baseURL = newBaseURL;
},
// 更新车型数据
updateVehicleTree(state, list) {
state.vehicleTree = list;
} }
} }
...@@ -11,7 +11,8 @@ const state = { ...@@ -11,7 +11,8 @@ const state = {
email: '', email: '',
gender: '', gender: '',
position: '' position: ''
} },
vehicleTree:[], // 车形数据
} }
try { try {
......
//浏览器indexDb封装
let _db = '';
let _indexDb = {};
/**
* 打开数据库、创建数据库
* name:数据库名称
* version:数据库版本号
*/
_indexDb.creatIndexDb = function (options) {
let oParams = options || {}
return new Promise((resolve, reject) => {
if (!window.indexedDB) {
console.log('您的浏览器暂时不支持indexDb');
return false;
}
_db = window.indexedDB.open(oParams.name || 'cookie', oParams.version || 1);
// 监听数据库打开失败、连接失败
_db.onerror = function (event) {
console.log('打开失败');
// if (oParams.onerror) {
// (oParams.onerror)(event)
// }
reject(event)
}
// 监听数据库打开成功
_db.success = function (event) {
console.log(_db.result)
console.log('打开成功');
// if (oParams.success) {
// (oParams.success)(event)
// }
resolve(event)
}
// 监听数据库升级事件
_db.upgradeneeded = function (event) {
// if (oParams.upgradeneeded) {
// (oParams.upgradeneeded)(event)
// }
resolve(event)
}
})
}
/**
* 添加数据
* key:存入数据库的键值
* data:存入数据库的值
*
*/
_indexDb.addItem = function (key,data) {
if (!_db) {
this.creatIndexDb().then(res => {
var request = db.transaction(['cookie'], 'readwrite')
.objectStore('person')
.put({ id: 1, name: '李四', age: 35, email: 'lisi@example.com' })
});
}
}
// 暴露方法
export const creatIndexDb = _indexDb.creatIndexDb;
export const addItem = _indexDb.addItem;
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
<script> <script>
import { getTableList, delelteTableRowData } from "services/vehicletype"; import { getTableList, delelteTableRowData } from "services/vehicletype";
import {creatIndexDb,addItem} from '@/utils/indexDb'
export default { export default {
name: "vehicleTypeManage", name: "vehicleTypeManage",
data() { data() {
...@@ -154,7 +155,11 @@ export default { ...@@ -154,7 +155,11 @@ export default {
}, },
created(){ created(){
}, },
mounted() {}, mounted() {
console.log(this.$store.state)
creatIndexDb();
addItem()
},
activated() {}, activated() {},
methods: { methods: {
// 重置搜索条件 // 重置搜索条件
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!