美文网首页
localStorage的使用方法以及一些注意事项

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

作者: 寒枫Alex | 来源:发表于2017-05-07 05:18 被阅读0次

    基本使用方法:

    [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会抛出异常.

    相关文章

      网友评论

          本文标题:localStorage的使用方法以及一些注意事项

          本文链接:https://www.haomeiwen.com/subject/nffutxtx.html