[Vue 警告]:v-on 处理程序中的错误:“TypeError:无法读取未定义的属性‘长度’”

问题描述

我正面临这个错误。我可以知道我的代码是否有问题吗?

validateEmail(){
  const emailregex = /^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$/
  const emailmatch = emailregex.test(this.userObj.user.email)
  if((!emailmatch) || (this.userObj.user.email.length == undefined)){
    this.errors = []
    console.log(this.userObj.user.email)
    this.errors.push("Email is not valid")
  }

我正在尝试使用正则表达式验证电子邮件地址

解决方法

可能 response = s3.generate_presigned_url( 'get_object',Params={ 'Bucket': 'myBucket','Key': filename,'ResponseContentDisposition': 'inline' } ) 未定义,尝试使用 optional chaining (?.) 像这样:

this.userObj.user.email

,

如果您不确定您的正则表达式是否有效,您可以在此处对照一些测试字符串进行检查:https://rubular.com/

这样,您将消除可能的正则表达式错误。