【问题标题】:problem with load nativeStorage at first run首次运行时加载 nativeStorage 的问题
【发布时间】:2019-05-16 09:58:58
【问题描述】:

我需要帮助来解决这个问题。 在 home.ts 中,我检查用户之前是否使用 nativeStorage 登录过

home.ts

ionViewWillEnter() {
  this.load();
}

load() {

  this.chk = this.gettoken();

  alert(this.chk)
  if (this.chk == 'true')

  {
    //// code here
  }

  gettoken(): Promise<string> {
    this.nativeStorage.getItem('isLoggedIn').then((value) => {
      this.val = value;
    });
    return this.val;
  };

}

在登录页面我使用这个保存到存储中:

this.nativeStorage.setItem('isLoggedIn','true');

第一次运行应用程序时,我得到了“未定义”,现在可以了。成功登录并关闭应用程序并再次运行后,我得到了“未定义” 我必须转到另一个页面并再次返回主页才能获取 storage 的值 (isLoggedIn) true

我把gettoken()改成这个:

async gettoken(){
    return await this.storage.getItem('isLoggedIn');
}   

但同样的问题

【问题讨论】:

    标签: ionic3


    【解决方案1】:

    那么你也需要等待.gettoken(),方法是:

    async load(){
        this.chk = await this.gettoken();
        alert(this.chk);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多