Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用以下代码将 key:value 设置为本地存储:
chrome.storage.local.set({"key": value}, null);
我该怎么做才能将多个值添加到键“key”?
首先使用该get方法,然后在回调set内部使用get,将您的新存储数据作为键/值对添加到从get. 例子:
get
set
chrome.storage.local.get(function(cfg) { if(typeof(cfg["key"]) !== 'undefined' && cfg["key"] instanceof Array) { cfg["key"].push("value"); } else { cfg["key"] = ["value"]; } chrome.storage.local.set(cfg); });