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()