localStorage存放数据自动转为String字符串,重新获取Boolean时非空字符串都为true。
解决方法:在存放时,如果为false,则设置空字符串;
localStorage.setItem('rememberPwd', this.rememberPwd ? 'true' : '')
本文介绍了一种解决LocalStorage中Boolean类型数据存储问题的方法。由于LocalStorage自动将数据转换为字符串,当读取Boolean值时会遇到非空字符串都被解释为true的情况。文章提供了解决方案:在存储时,若值为false则存为空字符串。
localStorage存放数据自动转为String字符串,重新获取Boolean时非空字符串都为true。
解决方法:在存放时,如果为false,则设置空字符串;
localStorage.setItem('rememberPwd', this.rememberPwd ? 'true' : '')
268
4089
3244

被折叠的 条评论
为什么被折叠?
