Coder Social home page Coder Social logo

addressbook-1's Introduction

IndexedDB初体验

在线访问地址: 在线预览

特点:

  1. 对象形式存储
  2. 异步 (防止锁死浏览器,localstorage是同步的
  3. 支持事物 (只要有一步失败,整个事物回滚
  4. 同源限制 (不能跨域访问数据库
  5. 存储空间比localstorage大 (大的多
  6. 支持二进制存储

我写了一个通讯录的项目,利用indexeddb在浏览器持续化端存储通讯录数据,支持通讯录导入,新增,搜索,修改,删除联系人

学习自: 阮一峰浏览器数据库 & indexedDB API

安装:

yarn install

运行:

yarn start

示例:

演示图片

我贴出大概示例:

// DB.ts

interface Idb {
	database: string; // 数据库名称
	version: number; // 版本号
	db: any; // 数据库创建成功后的对象
	store: any[]; // 初始化存储数据
	tables: any[]; // 表选项
	
	open(): void; // 打开数据库方法
	add(): void; // 插入一条数据
	read(i): void; // 读取指定数据
	readAll(): void; // 读取全部数据
	remove(i): void; // 移除指定数据
	update(o): void; // 更新指定数据
}

init.ts

import IndexedDB from './DB';
var db_person = new IndexedDB('db_test', 1);
db_person.open(); // 初始化数据库操作

addressbook-1's People

Contributors

yixiangtw avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.