localstoragesessionstorage 存储布尔值要注意

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')),再进行后续判断操做。对象

相关文章
相关标签/搜索