app.component("phone", {
template: "#phone",
setup() {
// TODO
let isSure = ref("");
let phoneVal = inject("phoneVal");
let code = inject("code");
let createCode = inject("createCode");
let data = inject("data");
return {};
}
});
实现 verifyPhone() 函数以检查手机号码的有效性:
function verifyPhone(num) {
if (num.length != 11) return false;
return num[0] == 1 && num[1] == 8;
}
实现 nextStep() 函数以处理“下一步”按钮的点击事件,phone 组件的所有代码如下:
app.component("phone", {
template: "#phone",
setup() {
// TODO
let isSure = ref("");
let phoneVal = inject("phoneVal");
let code = inject("code");
let createCode = inject("createCode");
let data = inject("data");
function verifyPhone(num) {
if (num.length != 11) return false;
return num[0] == 1 && num[1] == 8;
}
return {
isSure,
phoneVal,
nextStep() {
if (!isSure.value)
return ElNotification({
title: "发送失败",
message: "请阅读并同意以下协议",
type: "error"
});
if (!verifyPhone(phoneVal.value))
return ElNotification({
title: "发送失败",
message: "手机号码无效",
type: "error"
});
code.value = createCode();
ElNotification({
title: "发送成功",
message: "你的验证码是 " + code.value,
type: "success"
});
data.showName = "check";
}
};
}
});
"
You guys are awesome. love the way that labby breaks terms or syntax down to definitions and then a simple creative rewording to easily give a really good idea of what the concept in question, is."
— G-O Va-Knee
"
Good way to practice what was learned previously."