localStorage的使用方法以及一些注意事项

基本使用方法:

[Storage.key()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/key)
      //When passed a number n, this method will return the name of the nth key in the storage.

[Storage.getItem()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem)
      //When passed a key name, will return that key's value.
[Storage.setItem()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem)
      //When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.
[Storage.removeItem()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/removeItem)
      //When passed a key name, will remove that key from the storage.
[Storage.clear()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/clear)
   //When invoked, will empty all keys out of the storage.

其他:

  • 只能存储字符串
  • chrome 56下, 极限大小是5M左右.
  • Safari无痕模式下设置localStorage会抛出异常.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容