Vue.js 重置密码功能代码解析及优化
// 定义methods对象
methods: {
// 定义异步方法onResetPass
async onResetPass() {
// 判断是否输入了账号
if (this.username === undefined) {
this.$utils.msg('请输入账号');
return;
}
// 判断是否选择了角色
if (this.optionsValues[this.index] === '') {
this.$utils.msg('请选择角色');
return;
}
// 调用API接口resetPass重置密码
let res = await this.$api.resetPass(${this.optionsValues[this.index]}, this.username);
// 弹出消息提示框
this.$utils.msgBack('重置密码成功,原始密码为:123456');
},
// 定义optionsChange方法
optionsChange(e) {
// 将选中的角色的索引赋值给index
this.index = e.target.value;
},
// 定义styleChange方法
styleChange() {
// 使用$nextTick方法等待DOM更新后执行
this.$nextTick(() => {
// 获取所有class为forget-input的元素下的class为uni-input-input的元素,并设置其背景颜色为restPwFrom.content.input.backgroundColor
// (注释掉的代码可能是之前的实现方式)
// document.querySelectorAll('.forget-input .uni-input-input').forEach(el => {
// el.style.backgroundColor = this.restPwFrom.content.input.backgroundColor
// });
});
}
}
原文地址: https://www.cveoy.top/t/topic/kW4b 著作权归作者所有。请勿转载和采集!