我有一个问题,当我想将从axios帖子中获得的数据存储在localstorage中时,当我从localstorage获得数据时,我只会得到一个promise对象。我不知道该怎么办。有人能帮我吗 ?
function login(email, password) {
return axios.post('http://localhost:3001/users/login', {
email: email,
password: password,
}).then(response => {
return response.data.token
}).catch(function (error) {
console.log(error);
});
}
var t = login(email,password).then(data =>{
localStorage.setItem('token1',data)
})
localStorage.setItem('token2',t)
console.log('varT: '+t)
console.log('token1: '+localStorage.getItem('token1'))
console.log('token2: '+localStorage.getItem('token2'))