Vue.js Hot我可以使用LocalFower的退货吗
在我的Vue SPA中,我使用localfollow来存储承载令牌 在组件中,我需要令牌将文件上载到api 我试图获取LocalFower令牌:Vue.js Hot我可以使用LocalFower的退货吗,vue.js,localforage,Vue.js,Localforage,在我的Vue SPA中,我使用localfollow来存储承载令牌 在组件中,我需要令牌将文件上载到api 我试图获取LocalFower令牌: let token = localforage.getItem('authtoken') console.log(token) 它可以工作,但结果是一个承诺对象: Promise result: "eyJ0eXAiOiJKV1QiyuIiwiaWF0IjoxNTg4MTUzMTkzLCJleHAiOj
let token = localforage.getItem('authtoken')
console.log(token)
它可以工作,但结果是一个承诺对象:
Promise
result: "eyJ0eXAiOiJKV1QiyuIiwiaWF0IjoxNTg4MTUzMTkzLCJleHAiOjE1ODg…"
status: "resolved"
当我尝试console.log(token.result)
时,它返回null
如何访问令牌?说明了从存储器读取值的三种不同方法
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);
}
不要张贴代码、数据、错误消息等的图像-在问题中复制或键入文本。
localfower.getItem('authtoken')
是否确实在此处返回承诺?另外,您在localfour
中使用的插件是什么?@palaѕаа是的,承诺文本是从控制台复制的。您的问题在他们的文档中有完整的解释。