我试图访问我的vue.js组件中chrome浏览器的Chrome扩展的本地存储。在Vue.js组件中使用Chrome浏览器扩展API组件
ServerList.vue
<template>
<div>
<server-list :server-descriptions="serverDescriptions"/>
</div>
</template>
<script>
import ServerList from "./ServerList.vue"
chrome.storage.sync.set({'foo': 'hello', 'bar': 'hi'}, function() {
console.log('Settings saved');
});
chrome.storage.sync.get(['foo', 'bar'], function(items) {
console.log('Settings retrieved', items);
});
[...]
</script>
此代码是我popup.html内,这是什么popup.html检查控制台告诉我:
所以我假设它确实有效。但是,当我通过调试选项卡中勾选本地存储我什么也看不到:
即使检查控制台localStorage
手动不告诉我任何事情:
因此我假设数据在我的浏览器无法persistet浏览器吗?
有没有人知道我能如何让这个工作?或者给我一个提示?
'localStorage'不是chrome.storage.local保存数据的地方。请参阅[文档](https://developer.chrome.com/extensions/storage)。另外要注意后者是异步的。 – wOxxOm
相关:[window.localStorage vs chrome.storage.local](https://stackoverflow.com/q/24279495) – Makyen