wix-storage.Storage

wix-storage.Storage

Used for storing local or session key/value data in the user's browser.

To learn more about local and session storage, see wix-storage.

To use the Storage API, import the needed storage type(s) from the wix-storage module:

ICAgaW1wb3J0IHtsb2NhbCwgc2Vzc2lvbn0gZnJvbSAnd2l4LXN0b3JhZ2UnOwoKICAgLy8gT3Igb25lIG9mOgoKICAgaW1wb3J0IHtsb2NhbH0gZnJvbSAnd2l4LXN0b3JhZ2UnOwogICBpbXBvcnQge3Nlc3Npb259IGZyb20gJ3dpeC1zdG9yYWdlJzs=
   import {local, session} from 'wix-storage';

   // Or one of:

   import {local} from 'wix-storage';
   import {session} from 'wix-storage';

Contents

clear( ) Removes all items from local or session storage.
getItem( ) Gets an item from local or session storage.
removeItem( ) Removes an item from local or session storage.
setItem( ) Stores an item in local or session storage.
clear( )

clear( )

Removes all items from local or session storage.

function clear(): void

Examples

Remove all items from local storage

aW1wb3J0IHtsb2NhbH0gZnJvbSAnd2l4LXN0b3JhZ2UnOwoKLy8gLi4uCgpsb2NhbC5jbGVhcigpOwo=
import {local} from 'wix-storage';

// ...

local.clear();

Remove all items from session storage

aW1wb3J0IHtzZXNzaW9ufSBmcm9tICd3aXgtc3RvcmFnZSc7CgovLyAuLi4KCnNlc3Npb24uY2xlYXIoKTsK
import {session} from 'wix-storage';

// ...

session.clear();

See Also

remove( )

getItem( )

getItem( )

Gets an item from local or session storage.

function getItem(key: string): string

Parameters

key String The key of the item to get.

Return Value

String The retrieved item value.

Examples

Retrieve an item from local storage

aW1wb3J0IHtsb2NhbH0gZnJvbSAnd2l4LXN0b3JhZ2UnOwoKLy8gLi4uCgpsZXQgdmFsdWUgPSBsb2NhbC5nZXRJdGVtKCJrZXkiKTsgLy8gInZhbHVlIgo=
import {local} from 'wix-storage';

// ...

let value = local.getItem("key"); // "value"

Retrieve an item from session storage

aW1wb3J0IHtzZXNzaW9ufSBmcm9tICd3aXgtc3RvcmFnZSc7CgovLyAuLi4KCmxldCB2YWx1ZSA9IHNlc3Npb24uZ2V0SXRlbSgia2V5Iik7IC8vICJ2YWx1ZSIK
import {session} from 'wix-storage';

// ...

let value = session.getItem("key"); // "value"

See Also

setItem( )

removeItem( )

removeItem( )

Removes an item from local or session storage.

function removeItem(key: string): void

Parameters

key String The key of the item to remove.

Examples

Remove an item from local storage

aW1wb3J0IHtsb2NhbH0gZnJvbSAnd2l4LXN0b3JhZ2UnOwoKLy8gLi4uCgpsb2NhbC5yZW1vdmVJdGVtKCJrZXkiKTsK
import {local} from 'wix-storage';

// ...

local.removeItem("key");

Remove an item from session storage

aW1wb3J0IHtzZXNzaW9ufSBmcm9tICd3aXgtc3RvcmFnZSc7CgovLyAuLi4KCnNlc3Npb24ucmVtb3ZlSXRlbSgia2V5Iik7Cg==
import {session} from 'wix-storage';

// ...

session.removeItem("key");

See Also

clear( )

setItem( )

setItem( )

Stores an item in local or session storage.

function setItem(key: string, value: string): void

Parameters

key String The key of item to set.
value String The value of the item to set.

Examples

Store an item in local storage

aW1wb3J0IHtsb2NhbH0gZnJvbSAnd2l4LXN0b3JhZ2UnOwoKLy8gLi4uCgpsb2NhbC5zZXRJdGVtKCJrZXkiLCAidmFsdWUiKTsK
import {local} from 'wix-storage';

// ...

local.setItem("key", "value");

Store an item in session storage

aW1wb3J0IHtzZXNzaW9ufSBmcm9tICd3aXgtc3RvcmFnZSc7CgovLyAuLi4KCnNlc3Npb24uc2V0SXRlbSgia2V5IiwgInZhbHVlIik7Cg==
import {session} from 'wix-storage';

// ...

session.setItem("key", "value");

See Also

getItem( )