![](/img/trans.png)
[英]TypeError: Cannot read properties of undefined (reading 'createdTimestamp')
[英]TypeError: Cannot read properties of undefined (reading 'token')
當我使用 localStorage 我有這個錯誤:未捕獲(承諾)類型錯誤:無法讀取未定義的屬性(讀取“令牌”)。 但我的令牌在這里:
承諾在這里:
async loginSubmit () {
const response = axios.post('http://localhost:3000/api/auth/login', {
email: this.email,
password: this.password
});
localStorage.setItem('token', response.data.token);
console.log(response);
this.$router.push('actu');
},
你能幫助我嗎 ? 請
axios返回一個promise,需要等待請求:
const response = await axios.post(...)
您正在使用 axios,它返回一個承諾。 這就是為什么你有這個錯誤。 您必須使用 async await 來等待 axios 響應
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.