localstoragesessionstorage 存取數據方式:session
存儲字符、數字、布爾值等localstorage
存:localstorage.setItem('key', key-value);
取:localstorage.getItem('key');
存儲對象code
存:localstorage.setItem("key", JSON.stringift(key-value));
取:JSON.parse(localstorage.getItem('key'));
當 localstorage 或 sessionstorage 存儲布爾值
數據時,取到的數據變成了字符串'true' 'false'
,建議在存儲該類型數據時將 value 設置爲 0、1,取值時用Number(localstorage.getItem('key'))
,再進行後續判斷操做。對象