vue (storage method)

Cookie]    
1: Usage scenarios:
1: Remember the password, and log in automatically next time.
2: Record user browsing data and recommend products (advertisements).
Two: Features:
1: The cookie is saved on the browser side.
2: The data saved by a single cookie cannot exceed 4KB.
3: The data in the cookie is distinguished in the form of a domain name.
4: The data in the cookie has an expiration time, and the data will be automatically deleted by the browser after the expiration time. 5: The data in the cookie will be automatically sent to the server side along with the request.
Three:
Because the cookie storage mechanism has many shortcomings, HTML5 no longer uses it, and instead uses the improved WebStorage storage mechanism. (localStorage and sessionStorage)

The life cycle of SessionStorage   

The SessionStorage life cycle is the current window or tab page.    
Once the window or tab is permanently closed, all data stored by the Session will be cleared.


1. What is localstorage


In HTML5, a new localStorage feature has been added, which is mainly used as local storage.
It solves the problem of insufficient cookie storage space. The storage space of each cookie is 4K, and the localStorage is generally 5M.


 2. The life cycle of localStorage
 The life cycle of LocalStorage is permanent, which means that unless the user clears the localStorage information on the UI displayed on the browser, the information will exist permanently.  

 
3. Limitations of localStorage
a. The property of localstorage is only supported in IE versions above IE8.
b. At present, all browsers will limit the value type of localStorage to string type, and 11 needs a conversion for our daily common JSON object type.


 4. Determine whether the browser supports the localstorage property if(window.localstorage){ alert('browser supports localStorage')}


 5. Writing to localstorage

if(!window.localStorage){ alert('Browser does not support localStorage')

}else{
var storage = window.localstorage;

// Write a field
storage['a'] = 1;

// write to field b

storage.b = 2;

// Write to the c field
storage.setItem('c',3)
console.log(typeof storage['a']); //string

console.log(typeof storage['b']); //string

console.log(typeof storage['c']); //string}

 

 

 

 

Guess you like

Origin blog.csdn.net/m0_73495603/article/details/127325324