Javascript 参数Storageservice.prototype.setItem无效

Javascript 参数Storageservice.prototype.setItem无效,javascript,angular,local-storage,Javascript,Angular,Local Storage,当我尝试使用setItem在localstorage中设置数据并使用getItem获取数据时,chrome和firefox中的一切都很好,但在IE或Edge中不起作用 在边缘得到这些错误 未捕获(承诺中):错误:无效参数 参数Storageservice.prototype.setItem无效 未处理的承诺拒绝:无效参数,区域:角度; 任务:承诺;值:错误:参数无效。错误:无效 争论 在IE中: 例外情况:未捕获(承诺):QUOTAEEXCEEDERROR原件 STACKTRACE:错误:未捕获

当我尝试使用setItem在localstorage中设置数据并使用getItem获取数据时,chrome和firefox中的一切都很好,但在IE或Edge中不起作用

在边缘得到这些错误

未捕获(承诺中):错误:无效参数

参数Storageservice.prototype.setItem无效

未处理的承诺拒绝:无效参数,区域:角度; 任务:承诺;值:错误:参数无效。错误:无效 争论

在IE中:

例外情况:未捕获(承诺):QUOTAEEXCEEDERROR原件 STACKTRACE:错误:未捕获(承诺中):QuoteExceedeError
未处理的拒绝承诺:QuoteExceedeError;区域:角度; 任务:承诺;值:QuoteExceedeError未定义

我正在使用下面的代码片段-

setItem(key: string, data: any, storageType: string = 'localStorage'): any {
    let _storage: any = localStorage;
    if (storageType !== 'localStorage') {
      //sessionStorage maybe?
      _storage = sessionStorage;
    }

    let _data = this.transform('set', (typeof data === "string") ? data : JSON.stringify(data));
    _storage.setItem(key, _data);
  }


  /**
   * getItem(key) returns the cache object from storage
   */
  getItem(key: string, ifNotFound: any = {}, storageType: string = 'localStorage'): any {
    let _storage: any = localStorage;
    if (storageType !== 'localStorage') {
      //sessionStorage maybe?
      _storage = sessionStorage;
    }
    let _data = _storage.getItem(key);
    if (_data) {
      try {
        return JSON.parse(this.transform('get', _data));
      } catch (e) {
        return ifNotFound;
      }
    }
    return ifNotFound;
  }

  /**
   * transform() returns the object transformed to storage
   */
   transform(type: string = 'set', data: any): any {
     var isMSIE = (/trident/i).test(navigator.userAgent);
     if (isMSIE) {
       return data;
     } else {
       if (type === 'set') {
         //compress the data to Base64 and then do unicode encoding
          return LZString.compress(data);
         /*return this.encodeModal.encoder.compress(data);*/
       } else {
         //transform for fetch

         return LZString.decompress(data);
         //return this.encodeModal.encoder.decompress(data);
       }
     }
   }

到目前为止您尝试过的代码如何?@BelminBedak我已经更新了我的问题,请参阅。IE11中的配额超过错误我们需要使用LZString压缩数据并在会话存储中设置。