❤️砥砺前行,不负余光,永远在路上❤️
前言
uniapp + uview2.0 Code 验证码输入框 运行到支付宝小程序发验证码报错
(index):1 TypeError: Cannot read properties of undefined (reading 'canGetCode')
解决:项目详情勾选component2
如果倒计时还是不行:在异步之前调用倒计时
this.$refs.uCode.start();
sendCode () {
if (this.$refs.uCode.canGetCode) {
// 模拟向后端请求验证码
const regExp = RegExp(/^1[3456789]\d{9}$/);
if (regExp.test(this.loginObj.phone)) {
this.$refs.uCode.start();
uni.$http("/sndCode", "GET", { cellPhone: this.loginObj.phone }).then((res) => {
uni.$u.toast("验证码已发送");
this.$refs.uCode.start();
});
} else {
this.$u.toast("请输入手机号");
}
} else {
uni.$u.toast("倒计时结束后再发送");
}
},