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