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

相关推荐
掘金安东尼1 天前
纯 CSS 实现弹性文字效果
前端·css
牛奶1 天前
Vue 基础理论 & API 使用
前端·vue.js·面试
牛奶1 天前
Vue 底层原理 & 新特性
前端·vue.js·面试
anOnion1 天前
构建无障碍组件之Radio group pattern
前端·html·交互设计
pe7er1 天前
状态提升:前端开发中的状态管理的设计思想
前端·vue.js·react.js
SoaringHeart1 天前
Flutter调试组件:打印任意组件尺寸位置信息 NRenderBox
前端·flutter
晚风予星1 天前
Ant Design Token Lens 迎来了全面升级!支持在 .tsx 或 .ts 文件中直接使用 Design Token
前端·react.js·visual studio code
sunny_1 天前
⚡️ vite-plugin-oxc:从 Babel 到 Oxc,我为 Vite 写了一个高性能编译插件
前端·webpack·架构
GIS之路1 天前
ArcPy 开发环境搭建
前端
林小帅1 天前
【笔记】OpenClaw 架构浅析
前端·agent