mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
docs(): LocalStorage
This commit is contained in:
@@ -2,6 +2,8 @@ import {StorageEngine} from './storage';
|
||||
|
||||
|
||||
/**
|
||||
* @name LocalStorage
|
||||
* @description
|
||||
* The LocalStorage storage engine uses the browser's local storage system for
|
||||
* storing key/value pairs.
|
||||
*
|
||||
@@ -10,6 +12,20 @@ import {StorageEngine} from './storage';
|
||||
* by the operating system (iOS).
|
||||
*
|
||||
* For guaranteed, long-term storage, use the SqlStorage engine which stores data in a file.
|
||||
*
|
||||
* @usage
|
||||
* ```ts
|
||||
* import {Page, Storage, LocalStorage} from 'ionic/ionic';
|
||||
* @Page({
|
||||
* template: `<ion-content></ion-content>`
|
||||
* });
|
||||
* export class MyClass{
|
||||
* constructor(){
|
||||
* this.local = new Storage(LocalStorage);
|
||||
* this.local.set('didTutorial', true);
|
||||
* }
|
||||
*}
|
||||
*```
|
||||
* @demo /docs/v2/demos/local-storage/
|
||||
* @see {@link /docs/v2/platform/storage/ Storage Platform Docs}
|
||||
*/
|
||||
@@ -17,6 +33,11 @@ export class LocalStorage extends StorageEngine {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key in LocalStorage
|
||||
* @param {String} key the key you want to lookup in LocalStorage
|
||||
*/
|
||||
get(key) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@@ -27,6 +48,12 @@ export class LocalStorage extends StorageEngine {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a key value pair and save it to LocalStorage
|
||||
* @param {String} key the key you want to save to LocalStorage
|
||||
* @param {Any} value the value of the key you're saving
|
||||
*/
|
||||
set(key, value) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@@ -37,6 +64,11 @@ export class LocalStorage extends StorageEngine {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a key from LocalStorage
|
||||
* @param {String} key the key you want to remove from LocalStorage
|
||||
*/
|
||||
remove(key) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user