1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 前端登录页做个简单记住密码

前端登录页做个简单记住密码

时间:2019-09-20 00:44:45

相关推荐

前端登录页做个简单记住密码

前端登录页如何做记住密码

在一般的项目中,我们需要在登录页面点击登录时记住密码,比较方便下次登录时快速登录,这个时候我们需要在点击登录时判断记住密码是否为选中状态,如果是选中状态把用户名和输入框的值存入localStorage,如果未选中则清除存入的值。

//记住密码if (this.checked) {localStorage.setItem("username", this.username);localStorage.setItem("password", this.password);} else {localStorage.removeItem("username");localStorage.removeItem("password");}

在登录页面的created时获取localStorage的值,如果存在,直接给用户名、密码赋值,然后修改记住密码的按钮状态

this.username = localStorage.getItem("username");this.password = localStorage.getItem("password");// 判断是否记住密码if (typeof this.username == "string") {this.checked = true;} else {this.checked = false;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。