Javascript Vue.js Axios从本地存储获取值(LocalFow)返回promise对象而不是值

Javascript Vue.js Axios从本地存储获取值(LocalFow)返回promise对象而不是值,javascript,local-storage,vuejs2,axios,localforage,Javascript,Local Storage,Vuejs2,Axios,Localforage,我试图从中获取呼叫的值,但它不起作用 axios.get('https://api.example.org/api/?uname=' + this.$getItem('LSuname'), { withCredentials: true, headers: {'Authorization': 'Bearer ' + this.$getItem('LSmytoken')} }) 控制台中出现403错误: XHR加载失败:获取“” 我也尝试过this.$getItem('LSuname')

我试图从中获取呼叫的值,但它不起作用

axios.get('https://api.example.org/api/?uname=' + this.$getItem('LSuname'), {
  withCredentials: true,
  headers: {'Authorization': 'Bearer ' + this.$getItem('LSmytoken')}
})
控制台中出现403错误:

XHR加载失败:获取“”

我也尝试过
this.$getItem('LSuname')。然后(value=>{return value})
this.$getItem('LSuname')。然后(function(value){return value})
,但我得到了相同的403和错误的url,最后还有一个承诺

我能够正确返回值,而不会在vue中的其他位置出现问题,如下所示:

this.$getItem('LSuname').then(value => {
  console.log('uname:' + value)
})

看起来是这样的。$getItem是一个异步调用,它将返回一个
承诺
。这意味着您必须等待调用完成,然后才能调用任何依赖于这些异步调用返回值的代码

在您的情况下,您可以使用等待所有异步调用返回,然后再进行
axios.get
调用:

let unamePromise = this.$getItem('LSuname');
let mytokenPromise = this.$getItem('LSmytoken');

Promise.all([unamePromise, mytokenPromise]).then((vals) => {
  axios.get('https://api.example.org/api/?uname=' + vals[0], {
    withCredentials: true,
    headers: {'Authorization': 'Bearer ' + vals[1] }
  })
})

类似地(也许?)我无法从本地存储中获得一个简单的值,只显示在我的页面上,有指针吗?(我尝试将其设置为计算值,一种方法,尝试向数据中添加类似
fullname:this.$getItem('LSfullname')
,但没有任何效果。正如我所说,
this.$getItem()
总是会返回一个承诺。如果将
fullname
设置为
this.$getItem('LSfullname'))
,则
全名
将是承诺,而不是异步函数的结果。您可以在此处阅读承诺:我尝试使用相同的承诺。上面所有语法都返回值,但它也失败了。而且似乎没有办法直接从本地存储中获取值。我将阅读,感谢链接。