Cookie LocalStorage SessionStorage對比
Cookie LocalStorage SessionStorage對比
三者異同
操作
localStorage和sessionStorage都具有相同的操作方法,例如setItem、getItem和removeItem等
set方法:
setStore (name, content) {
if (!name) return
if (typeof content !== 'string') {
content = JSON.stringify(content)
}
window.localStorage.setItem(name, content)
}
get方法:
getStore (name) {
if (!name) return
return JSON.parse(window.localStorage.getItem(name))
}
remove方法:
removeStore (name) {
if (!name) return
window.localStorage.removeItem(name)
}
cookie操作
由於js原生cookie介面不友好,建議使用js-cookie
$ npm install js-cookie --save
import Cookies from 'js-cookie'
Cookies.set('name', 'value', { expires: 365 });
Cookies.get('name');
Cookies.remove('name');
相關文章
- cookie、sessionStorage、localStorageCookieSession
- cookie, sessionStorage, localStorageCookieSession
- localStorage、sessionStorage、Cookie的SessionCookie
- localStorage 與 sessionStorage / cookie 和 sessionSessionCookie
- 詳說 Cookie, LocalStorage 與 SessionStorageCookieSession
- cookie、sessionStorage、localStorage的區別?CookieSession
- 深入瞭解瀏覽器儲存:對比Cookie、LocalStorage、sessionStorage與IndexedDB瀏覽器CookieSessionIndex
- Cookie && Session && localStorage && sessionstorage && HTTP快取CookieSessionHTTP快取
- localStorage、sessionStorage、Cookie的區別及用法SessionCookie
- localStorage,sessionStorage和cookie的區別及使用SessionCookie
- 理解cookie、session、localStorage、sessionStorage的關係與區別CookieSession
- Cookie、localStorage 和 sessionStorage 的區別及應用例項CookieSession
- 前端存貯全家桶--cookie、sessionStorage、localStorage、和indexedDB重點合集前端CookieSessionIndex
- localStorage和sessionStorage區別Session
- localStorage與sessionStorage 區別Session
- Yet another intro for localStorage and sessionStorageSession
- web本地儲存(localStorage、sessionStorage)WebSession
- sessionStorage和localStorage的區別Session
- cookies sessionStorage和localstorage區別CookieSession
- 【基礎梳理】cookie、session、sessionStorage、localStorage之間的區別及應用場景CookieSession
- localStorage和sessionStorage原型方法新增Session原型
- localStorage和SessionStorage,Application,Cache快取SessionAPP快取
- localStorage和sessionStorage儲存封裝Session封裝
- 移動Web——localStorage,sessionStorage,Storage事件監聽WebSession事件
- cookie,session,sessionStorage,localStotage的區別CookieSession
- H5本地儲存:sessionStorage和localStorageH5Session
- 請描述一下cookies、sessionStorage和localStorage的區別?CookieSession
- HTML5本地儲存localStorage與sessionStorage詳解HTMLSession
- 登入過期--localStorage加sessionStorage實現7天登入過期Session
- 系統登入認證流程對比(cookie方式與jwt)CookieJWT
- 2020-12-26 JavaScript基本概念5:cookie,sessionStorage和localStorage,0.1+0.2!=0.3怎麼處理,陣列的常用方法,new一個物件的過程,繼承JavaScriptCookieSession陣列物件繼承
- sessionStorageSession
- sessionStorage 用法Session
- 對session和cookie的理解SessionCookie
- localStorage 用法
- sessionStorage.lengthSession
- sessionStorage.removeItem()SessionREM
- sessionStorage.setItem()Session