dexie.js,封装了indexedDB本地数据库的插件。更方便使用indexedDB


indexedDB:用于本地存储大量数据,高达250M,离线功能的数据存储。

 

script引入使用

https://unpkg.com/dexie@latest/dist/dexie.js

创建数据库与增删改查

const db = new Dexie("db");
//++id表示自增的字段
db.version(1).stores({
    friends: '++id,name,age',
});

//新增1条数据
function add(obj) {
    db.friends.add(obj)
}

//修改1条数据 要带上主键 如id
function update(obj) {
    db.friends.put(obj)
}

//删除数据
function del(key) {
    db.friends.delete(key)
}

//查询数据
async function get(key) {
    return db.friends.get(key)
}

async function init() {
    console.log(await get(3))
}
init()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM