如何将axios帖子中的数据存储在localstorage中

时间:2019-07-11 10:09:42

标签: javascript axios

我有一个问题,当我想将从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'))

Output

0 个答案:

没有答案