我正在使用Vue3
和Vuetify
,当为确认密码字段的v-textfield
制定规则时,我遇到了这个错误:
I tried to compare the values of the password field and the one of the confirm password field, both associeted to the v-textfield
with the v-model
, but in the confirm password rule the variable of the password results undefined.
Here's the source.
Data whit rules and variables:
data: () => ({
// Credentials
username: '',
password: '',
confirmPassword: '',
passwordRules: [
(value) => {
if (value?.trim().length > 0) return true
else return 'Password is required.'
},
],
confirmPasswordRules: [
(value) => {
if (value?.trim().length > 0) {
// TODO: ERROR (this.password is undefined)
if(value === this.password) {
return true
}
else return 'Passwords do not match.'
}
else return 'Confirm password is required.'
},
],
}),
当我在v-textfield
中写入字符时,错误总是出现,因为它在规则中:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'password')
at confirmPasswordRules
谢谢!