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

相关推荐
烂蜻蜓39 分钟前
HTML 表格的详细介绍与应用
开发语言·前端·css·html·html5
圣京都2 小时前
react和vue 基础使用对比
javascript·vue.js·react.js
returnShitBoy2 小时前
前端面试:axios 是否可以取消请求?
前端
u0103754562 小时前
fiddler+雷电模拟器(安卓9)+https配置
前端·测试工具·fiddler
海上彼尚3 小时前
Vue3中全局使用Sass变量方法
前端·css·sass
ᥬ 小月亮3 小时前
TypeScript基础
前端·javascript·typescript
鱼樱前端3 小时前
Vue3+TS 视频播放器组件封装(Video.js + Hls.js 最佳组合)
前端·javascript·vue.js
烛阴3 小时前
JavaScript 函数进阶之:Rest 参数与 Spread 语法(二)
前端·javascript
GISer_Jing3 小时前
ES6回顾:闭包->(优点:实现工厂函数、记忆化和异步实现)、(应用场景:Promise的then与catch的回调、async/await、柯里化函数)
前端·ecmascript·es6
天天向上10243 小时前
vue项目清理node_modules缓存
前端·vue.js·缓存