Hot 可以用localforage的return吗

Hot can I use the return of localforage

在我的 Vue SPA 中,我使用 localforage 来存储 Bearer 令牌。

在组件中,我需要令牌才能将文件上传到 api。

我试图获取 localforage 令牌:

            let token = localforage.getItem('authtoken')
            console.log(token)

有效,但结果是一个 promise 对象:

Promise

result: "eyJ0eXAiOiJKV1QiyuIiwiaWF0IjoxNTg4MTUzMTkzLCJleHAiOjE1ODg…"

status: "resolved"

当我尝试 console.log(token.result) 它 returns null

我如何访问令牌?

official documentation 陈述了从存储中读取值的三种不同方法。

localforage.getItem('authtoken').then(function(value) {
    // This code runs once the value has been loaded
    // from the offline store.
    console.log(value);
}).catch(function(err) {
    // This code runs if there were any errors
    console.log(err);
});

// Callback version:
localforage.getItem('authtoken', function(err, value) {
    // Run this code once the value has been
    // loaded from the offline store.
    console.log(value);
});

// async/await
try {
    const value = await localforage.getItem('authtoken');
    // This code runs once the value has been loaded
    // from the offline store.
    console.log(value);
} catch (err) {
    // This code runs if there were any errors.
    console.log(err);
}