微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

elementUI表单的自动验证

methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
//https://element.eleme.cn/#/zh-CN/component/form

在这里插入图片描述


codeSign() {
    let mobile = /^[1][3,4,5,7,8,9][0-9]{9}$/

    if (!this.mobileFrom.mobile) {
      this.$message.error('请输入手机号')
      return false
    }

    if (!mobile.test(this.mobileFrom.mobile)) {
      this.$message.error('手机号格式不正确,请重新输入')
      return false
    }

    if (!this.mobileFrom.code) {
      this.$message.error('请输入验证码')
      return false
    }

    if (!this.protocolFlag) {
      this.$message.error('请先阅读用户 隐私协议 以及 服务协议')
      return false
    }

    this.setLoginType('Basic cG5hYXM6cG5hYXM=')
    const form: any = this.$refs.mobileFrom
    if (form.validate) {
      form.validate((valid: boolean) => {
        if (valid) {
          LoginApi.phoneLogin(this.mobileFrom.mobile, this.mobileFrom.code)
            .then((resp: any) => {
              if (resp.is_first == 1) {
                this.$message.success('登录成功')
                this.setUser(resp)
                this.setLoginType('Bearer ')
                this.$router.push({
                  path: '/setUserInfo',
                  query: {
                    phone: this.mobileFrom.mobile
                  }
                })
              } else {
                this.$message.success('登录成功')
                this.setUser(resp)
                this.setLoginType('Bearer ')
                this.$router.push('/')
              }
            })
            .catch(error => {
              this.$message.error(error.message)
            })
        }
      })
    }
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐