uni-app & vue2 记住密码功能

1. html代码

html 复制代码
<checkbox-group @change="checkboxChange">
	<label>
		<checkbox value="" :checked="ifSavePwd" style="transform: scale(0.6);"/>记住密码
	</label>
</checkbox-group>

2. js代码

默认复选款是不选中 在 data 里定义 SavePwd : false

javascript 复制代码
checkboxChange(e) {
	this.ifSavePwd = !this.ifSavePwd
	this.savePwd()
},

savePwd() {
	uni.setStorageSync('ifSavePwd', this.ifSavePwd)
	if (this.ifSavePwd === true) {
		console.log('保存用户密码')
		if (this.username) {
			uni.setStorageSync('username', this.username)
		}
		if (this.password) {
			uni.setStorageSync('password', this.password)
		}
	} else if (this.ifSavePwd === false) {
		console.log('无需保存用户密码')
		uni.removeStorageSync('username')
		uni.removeStorageSync('password')
	}
},

3. 效果

相关推荐
Shirley~~19 分钟前
leetcode移除元素
javascript·数据结构·算法
AC赳赳老秦23 分钟前
Prometheus + DeepSeek:自动生成巡检脚本与告警规则配置实战
前端·javascript·爬虫·搜索引擎·prometheus·easyui·deepseek
接着奏乐接着舞。25 分钟前
前端大数据渲染性能优化:Web Worker + 分片处理 + 渐进式渲染
大数据·前端·性能优化
Beginner x_u33 分钟前
CSS 中的高度、滚动与溢出:从 height 到 overflow 的完整理解
前端·css·overflow·min-height
vx1_Biye_Design38 分钟前
基于web的物流管理系统的设计与实现-计算机毕业设计源码44333
java·前端·spring boot·spring·eclipse·tomcat·maven
摘星编程1 小时前
React Native + OpenHarmony:Animated 弹簧动画实现代码
javascript·react native·react.js
tqs_123451 小时前
倒排索引数据结构
java·前端·算法
a程序小傲1 小时前
听说前端又死了?
开发语言·前端·mysql·算法·postgresql·深度优先
Yan.love1 小时前
【CSS-布局】终极方案:Flexbox 与 Grid 的“降维打击”
前端·css
曲幽1 小时前
JavaScript流程控制:从混乱条件到优雅遍历,一次讲清如何让代码听话
javascript·web·js·for·while·if·if else