loginUser(user: any) {
return this.http.post(this.loginUrl, user)
.subscribe((success: any) => {
if(success) {
localStorage.setItem('access_token', success.token);
localStorage.setItem('token', JSON.stringify(success.token));
return true;
}
});
}
返回的内容https://i.imgur.com/Km8X2CX.png 导致存储https://i.imgur.com/FfsOTb5.png
我要存储令牌的值
将其更改为
localStorage.setItem('access_token', success);
localStorage.setItem('token', JSON.stringify(success));
答案 0 :(得分:2)
您应该改为设置success.success.token。
更好地将响应重命名为response
loginUser(user: any) {
return this.http.post(this.loginUrl, user)
.subscribe((response: any) => {
if(response) {
localStorage.setItem('access_token', response.success.token);
// localStorage.setItem('token', JSON.stringify(response.success.token)); probably not needed.
return true;
}
});
}
答案 1 :(得分:0)
您在响应对象上有不必要的包装。删除它或使用response.success.token来获取令牌字符串。
您的代码变为:
output_x |= (((INPUT_1 | INPUT_2 | INPUT_3 | ... ) != 0) << 15);