我正在尝试验证两个密码是否匹配,如果不匹配则显示错误。但是,错误消息没有显示在我的 Vue 组件中。这是我的代码的相关部分:
const issues = ref<FlatErrors<typeof UserSchema>['nested']>();
const UserSchema = pipe(
object({
email: pipe(
string(),
nonEmpty('Email is required'),
email('The email must be in the format [email protected]')
),
password: pipe(
string(),
nonEmpty('Password is required'),
minLength(6, 'Password must be at least 6 characters long')
),
confirmPassword: string(),
}),
forward(
partialCheck(
[['password'], ['confirmPassword']],
input => input.password === input.confirmPassword,
'Passwords do not match'
),
['confirmPassword']
)
);
// template
<template v-if="issues?.confirmPassword">
<span
class="register__errors"
v-for="(issue, i) in issues.confirmPassword"
:key="i"
>{{ issue }}</span
>
</template>
确保架构验证
确保partialCheck函数在密码和确认密码不匹配时解决问题
还有
确保这部分在问题代码中
if (data.password !== data.confirmPassword) {
issues.value.confirmPassword = ['Passwords do not match'];
}