With the rapid development of the Internet, web-based applications are becoming more and more common, but also becoming more and more complex. In order to meet various needs, large amounts of data are often stored locally. The HTML5 specification proposes relevant solutions.

1. Local storage feature

1. Data is stored in the user’s browser

2, easy to set, read, and even page refresh without loss of data

3, large capacity, sessionStorage about 5M, localStorage about 20M

4, can only store strings, can encode the object json.stringify () store

2. window.sessionStorage

1. The lifecycle is to close the browser window

2. Data can be shared in the same window (page)

3. Store and use in the form of key-value pairs

Storing data:

sessionStorage.setItem(key, value)
Copy the code

Get data:

sessionStorage.getItem(key)
Copy the code

Delete data:

sessionStorage.removeItem(key)
Copy the code

Clear data :(all cleared)

sessionStorage.clear()
Copy the code

3. window.localStorage

1, declare that the cycle is permanent, unless manually deleted or closed page will exist

2. Multiple Windows (pages) can be shared (the same browser can be shared)

3. Store them as key-value pairs

Storing data:

localStorage.setItem(key, value)
Copy the code

Get data:

localStorage.getItem(key)
Copy the code

Delete data:

localStorage.removeItem(key)
Copy the code

Clear data :(all cleared)

localStorage.clear()
Copy the code