javascript - 签名完成后在 activeuser 上接收 null
问题描述
我正在使用本地存储来存储用户名和密码 在这行代码之后我的活动用户为空,我不知道为什么
console.log("I am the Active user: " + activeUser);
const menuChannelIcon = $(".menu-channel-icon");
const bellIcon = $(".bell-btn");
const uploadButtonIcon = $(".upload-btn");
const signInMainPageIcon = $(".signInMainPage");
const signUpMainPageIcon = $(".signUpMainPage");
const signOutMainPageIcon = $(".signOutMainPage");
const videoSectionMainPage = $(".video-section");
const signin = () => {
console.log("signin button clicked")
if (localStorage.getItem("formData")) {
// as long as you are getting items from the local storage... do..
JSON.parse(localStorage.getItem("formData")).forEach((data) => {
let x = $("#signEmail").val();
let z = $("#signinPassword").val();
if (data.email == x && data.pwd == z) {
isLogged = true;
activeUser = localStorage.getItem(email);
console.log("I am the Active user: " + activeUser);
menuChannelIcon.show();
bellIcon.show();
uploadButtonIcon.show();
signInMainPageIcon.hide();
signUpMainPageIcon.hide();
signOutMainPageIcon.show();
singIn_formContainer.hide();
videoSectionMainPage.show();
console.log("You are LOGGED");
}
});
}
};
编辑:在注册期间设置电子邮件和密码
解决方案
Barmar 在评论中发布的答案:localStorage.getItem("email")
替代答案:当电子邮件和密码与 formData 中的某些内容匹配时,活动用户不应该是 x 吗?为什么要从本地存储中获取活动用户?
推荐阅读
- python - Python 将 2 列转换为 JSON,例如带有额外的引号
- reactjs - 当 observable 发射时更新组件中的 UI
- python - 为什么在熊猫中将excel电子表格转换为数据框时找不到我的文件
- excel - 与 excel direct 中的实际公式相比,UDF 给出不同的结果
- python - 使用 Django 注释字段超集的计数
- typescript - 如果是Typescript中给定字符串的子字符串,如何选择属性
- angular - Angular ngOnInit() 属性不更新值
- xcode - Xcode 显示“该文档有 4 个已发现并修复的问题。/多个资源具有相同的名称:groupTableViewBackgroundColor。” 警报
- javascript - 使用 Tribute.js 使用 Ajax 加载数据以进行提及
- r - 将 ggplot2 中的图例与拼凑(离散/分类数据)组合和合并