简体   繁体   English

Chrome扩展程序的本地存储

[英]localstorage on chrome extension

How I store date on chrome. 我如何在chrome上存储日期。 I tried localstorage but stupid reason they won't it allow. 我尝试了localstorage,但出于愚蠢的原因,他们不允许这样做。 I tied cookies but no. 我绑饼干,但没有。 Is away store any data at all. 根本不存储任何数据。 I tried chrome.storage but that not defined. 我尝试了chrome.storage,但未定义。 How do I fix this? 我该如何解决?

You should be using chrome.storage with your extension. 您应该在扩展程序中使用chrome.storage I can't tell you what you're doing wrong without seeing your code, but make sure you have the permission set correctly in your manifest: 在看不到代码的情况下,我无法告诉您您在做什么错,但是请确保您在清单中正确设置了权限:

{
  "name": "My extension",
   ...
  "permissions": [
  "storage"
],
...
}

Please provide an example of how you're trying to access chrome.storage and localStorage . 请提供一个示例,说明您如何尝试访问chrome.storagelocalStorage

Friend you need to share code also . 朋友,您还需要共享代码。 If i understood your question clearly you should go like this 如果我清楚地理解了你的问题,你应该这样

  var car = {};
    car.wheels = 4;
    car.doors = 2;
    car.sound = 'vroom';
    car.name = 'Lightning McQueen';
    console.log( car );
    localStorage.setItem( 'car', car );
    console.log( JSON.parse( localStorage.getItem( 'car' ) ) );

This is how local storage get use . 这就是本地存储的使用方式。 If still problem is there use window.localStorage.setItem and window.localStorage.getItem 如果仍然存在问题,请使用window.localStorage.setItem和window.localStorage.getItem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM