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. 效果

相关推荐
踢足球09295 小时前
寒假打卡:2026-2-7
java·开发语言·javascript
_果果然5 小时前
这 7 个免费 Lottie 动画网站,帮你省下一个设计师的工资
前端
QT.qtqtqtqtqt5 小时前
uni-app小程序前端开发笔记(更新中)
前端·笔记·小程序·uni-app
楚轩努力变强5 小时前
iOS 自动化环境配置指南 (Appium + WebDriverAgent)
javascript·学习·macos·ios·appium·自动化
Aliex_git5 小时前
跨域请求笔记
前端·网络·笔记·学习
John_ToDebug6 小时前
引擎深处的漫游者:构建浏览器JavaScript引擎的哲学与技艺
javascript·chrome·js
37方寸6 小时前
前端基础知识(Node.js)
前端·node.js
程序猿阿伟6 小时前
《TypeScript中Protobuf到运行时类型安全的转换指南》
javascript·安全·typescript
powerfulhell6 小时前
寒假python作业5
java·前端·python
木子啊6 小时前
前端组件化:模板继承拯救发际线
前端