After understanding some basic local storage usage and ideas, let's introduce the local storage system.
Local storage is divided into three main categories: localstorage/sessionstorage/local Database
The use of Localstorage and Sessionstorage, the functions contained, the methods of invocation, etc. are all the same, and they are just different meanings. The data stored by Localstorage is long-term, and the information stored by Sessionstorage is destroyed when each session is closed (popularly speaking, the data is automatically destroyed when the page is closed).
Because of the different characteristics of the two, the application of the scene also has a very big difference. In general, when we need to store some user configuration items and other data that need to be stored for a long time, we need to use Localstorgae to save, take advantage of its aging long characteristics. Accordingly, we need to use sessionstorage when we need to implement session-based functions like shopping carts.
Since the usage of localstorage and sessionstorage is the same, we take localstorage as an example to introduce the methods of both.
1. Set the data SetItem
The usage is Localstorage.setitem ("key", "value"), which means the value is passed to key. (Sessionstorage.setitem using the same method, the following no longer described below)
2. Get Data GetItem
The usage is Localstorage.getitem ("key"), as long as the corresponding key value is entered, the corresponding value value can be extracted from it.
3. Delete specific data RemoveItem
Use Localstorage.removeitem (key) to delete the data corresponding to key.
4. Clear All data
The usage is localstorage.clear (), which means emptying data from all storage systems.
These are some of the most basic sessionstorage/localstorage usages.
HTML5 Mobile Development Practical knowledge-local storage (2)