将 Ionic 存储项作为字符串获取

Get Ionic storage item as a string

正如标题所说,我的问题是当我这样做时:

this.storage.get('user')

我明白了object

t {__zone_symbol__state: null, __zone_symbol__value: Array(0)}

而且我不知道如何操作它。

我想问是否有办法从我的存储中获取字符串值 示例

// when i store user id like that 
this.storage.set("user", JSON.stringify(userID));
console.log(this.storage.get('user'))//output 100 for example

离子存储returns 数据的承诺。因此,您必须等待承诺得到解决并获取如下数据:

this.storage.get('user').then((result) => {
      console.log('My result', result);
});

接受的答案确实有效。由于 follow-up 评论询问如何使用存储中的结果字符串,因此另一种方法是使用 async/await 来处理承诺。这可以清除嵌套 .then()

的潜在混乱
let result: string = await this.storage.get('user');
//Use result here