我正在制作一个小 Chrome 扩展,并且我已成功使用选项页面来使用 chrome.storage.sync.set 来设置变量 pws。但是,在弹出页面上,我无法成功检索变量并在字符串中使用它。这是它的代码:
weather.open("GET", "http://api.wunderground.com/api/"+WU_API_KEY+"/conditions/q/CA/pws:"+pws+".json", true);
weather.send()
})
如何从 chrome.sync.storage.get 获取 pws 作为变量?
我尝试过类似的方法
chrome.storage.sync.get(pws, function(result){
var pws = result.pws
console.debug('result:',pws);
});
但没有效果。
最佳答案
如果您使用“pws”
作为存储pws
的 key ,那么您可以:
chrome.storage.sync.get("pws", function(result) {
var pws = result.pws;
console.log("result:", pws);
});
关于javascript - 使用 chrome.storage.get 获取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36708675/