uniapp
#login.vue
onReady() {//记住密码
//缓存的账号
const QS_username = uni.getStorageSync('QS_username');
//缓存的密码
const QS_password = uni.getStorageSync('QS_password');
console.log("缓存的账号:"+QS_username)
console.log("缓存的密码:"+QS_password)
//有缓存就赋值给文本没有就清空
if (QS_username && QS_password) {
this.username = QS_username;
this.password = QS_password;
} else {
this.username = '';
this.password = '';
}
//自动登录
},
//复选框
checkboxChange: function(e) {
console.log("复选框状态:"+e.detail.value.length);
if (e.detail.value.length == 1) {
//获取缓存的账号 赋值
uni.getStorageSync('QS_username',this.username);
uni.getStorageSync('QS_password',this.password);
} else {//销毁
uni.removeStorageSync('QS_username');
uni.removeStorageSync('QS_password');
}
},
uni.request({
url: $config.urls.get_token,
method: 'POST',
data: {
username: this.username,
password: this.password
},
success: (res) => {
console.log(res);
//勾选就缓存账号和密码
if (this.rememberPsw) {
uni.setStorageSync('QS_username', this.username);
uni.setStorageSync('QS_password', this.password);
} else {//销毁缓存
uni.removeStorageSync('QS_username');
uni.removeStorageSync('QS_password');
}
if (res.statusCode==200){
this.jwt_token = res.data.access
this.uid = res.data.uid
$config.user.set_user(this.username, this.uid, res.data.access)
uni.switchTab({
url:'/pages/my/my'
});
}else{
uni.showToast({
title: res.errMsg,
icon:'none'
});
}
},
fail: (err) => {
console.log(err);
},
complete: () => {}
});
====
<!-- 记住密码功能 --> <view class="item"> <checkbox-group @change="checkboxChange"> <checkbox id="chkRem" type="checkbox" :checked='rememberPsw' @tap="rememberPsw =! rememberPsw" color="#09CC86"/> <text class="remember_pwd">记住账号密码</text> </checkbox-group> </view>
data() {
return {
username:'',
password:'',
rememberPsw: true, //复选框状态 默认勾选
}
},
但有个问题,存储的密码是明文
? 需要寻找加密方案=》
· 一次 .NET 性能优化之旅:将 GC 压力降低 99%
· MySQL索引完全指南:让你的查询速度飞起来
· 一个字符串替换引发的性能血案:正则回溯与救赎之路
· 为什么说方法的参数最好不要超过4个?
· C#.Net 筑基-优雅 LINQ 的查询艺术
· 一次 .NET 性能优化之旅:将 GC 压力降低 99%
· 我用这13个工具,让开发效率提升了5倍!
· 32岁入行STM32迟吗?
· C#.Net筑基-泛型T & 协变逆变
· Coze工作流实战:一键生成鸡汤视频——厉害的人,早已戒掉情绪