什么'简单存储和本地存储的区别是什么

what's the difference between simple storage and localStorage?

本文关键字:存储 区别 是什么 简单 什么      更新时间:2023-09-26

在chrome扩展开发中,我们可以使用localStorage来存储我们需要的东西。我可以在使用AddonBuilder的firefox插件开发中使用localStorage吗?我见过很多使用simple-storage的萤火虫插件项目,simple-storagelocalStorage有什么区别?

Jetpack插件的主脚本无法访问任何DOM方法,包括localStorage。因此,simple-storage是这种API的自然替代品。此外,localStorage只能保存字符串值,而simple-storage能够保存布尔值、数字、数组、null和普通对象。

如果要将此类非String值保存在localStorage中,则必须使用JSON.parseJSON.stringify手动解析和序列化对象。simple-storage提供了一个简单的API来设置和获取值。

(旁注:Chrome的chrome.storage API可用于保存非字符串值,但方法是异步的,不同于Firefox的同步simple-prefs API。)