Vue uses the browser to store chat records

LocalStorage and SessionStorage are collectively referred to as WebStorage
1. The storage content size generally supports about 5MB (different browsers may not be the same)
2. The browser implements the local storage mechanism through Window.sessionStorageand attributes 3. Related APIs: 1.xxxxxStorage.setItem( " key' , "value"); This method accepts a key and value as parameters, and will add the key-value pair to the storage. If the key name exists, update its corresponding value 2.xxxxxStorage.getItem( "person"); This method Accept a key name as a parameter and return the value corresponding to the key name 3.xxxxxStorage.removeItem("key"); This method accepts a key name as a parameter and deletes the key name from the storage 4.xxxxxStorage.clear() the The method will clear all data in the storage 4. Remarks: 1. The content stored in SessionStorage will disappear with the browser window closedWindow.localStorage










2. The content stored in LocalStorage needs to be manually cleared before disappearing (call api or clear the cache)
3. xxxxStorage.getItem(xxx), if the value corresponding to xxx cannot be obtained, then the return value of getltem is null
4.JSON.parse The result of (null) is still null

We can convert other data types into strings through parse and stringify provided by the JSON object, and then store them in storage . Please see the code below.

var obj = { name:'Jim' };

var str = JSON.stringify(obj);

//deposit

sessionStorage.obj = str;

// read

str = sessionStorage.obj;

// convert back to object

obj = JSON.parse(str);

Guess you like

Origin blog.csdn.net/qq_42080594/article/details/130056364