【发布时间】:2021-10-01 20:47:48
【问题描述】:
当有人尝试编辑用户时,我正在尝试使用 vuetify 输入检查用户在 vue 中是否存在。如果用户名已经存在,那么我会抛出一个错误,除非这个用户名是旧用户名,如果当时正在编辑的用户没有更改他的名字。 但是它调用我的函数的模式似乎坏了,但我不知道为什么,我已将函数放入规则中:
nameRules: [
v => !!v || 'Obrigatory field',
v => (v && (v.length <= 20 && v.length >= 2)) || 'Less than 20 and more than 2 characters',
v => ( v && (/^[a-z0-9]+$/.test(v))) || 'Only digits and lowercase letters',
v => ( v && this.checkUserExistence(v)) || 'User already exists'
]
功能:
checkUserExistence(v){
this.usersdata.some(user => {
if(user.username != this.oldusername){
return user.username == v
}
else {
return true
}
})
看起来它忽略了真/假语句并显示错误! },
【问题讨论】:
-
在
checkUserExistence中添加debugger,this.usersdata是什么样的? -
我已经试过了。它应该正确返回,但事实并非如此。它是一个对象数组。
-
能不能把这个数组贴出来或者举个例子看看,不然很难调试
标签: vue.js vuetify.js