Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在vuejs中验证电子邮件?_Javascript_Regex_Vue.js - Fatal编程技术网

Javascript 如何在vuejs中验证电子邮件?

Javascript 如何在vuejs中验证电子邮件?,javascript,regex,vue.js,Javascript,Regex,Vue.js,电子邮件字段是必需的。 仅30个字符{{$v.user.password.$params.maxLength.min} 我总是使用。简单明了。 你可以做的最大长度和更多!此外,您甚至可以检查Vue Devtools中哪些部件是“脏的”! 示例代码: <template> <input required="required" v-model="email" :error-messages="emailErrors"


电子邮件字段是必需的。
仅30个字符{{$v.user.password.$params.maxLength.min}
我总是使用。简单明了。 你可以做的最大长度和更多!此外,您甚至可以检查Vue Devtools中哪些部件是“脏的”! 示例代码:

<template>
   <input required="required" v-model="email" :error-messages="emailErrors"
   @input="$v.email.$touch()" @blur="$v.email.$touch()" label="Email*"
   prepend-icon="mdi-email"></input>
</template>

<script>
import { validationMixin } from 'vuelidate'
import { required, email, ... } from 'vuelidate/lib/validators'
import { mapActions } from "vuex";
export default {

mixins: [validationMixin],
validations: {
    ...,
    email: { required, email },
    ...
},
data: () => ({ email: '', ... })
computed: {
    emailErrors () {
        const errors = []
        if (!this.$v.email.$dirty) return errors
        !this.$v.email.email && errors.push('Must be valid e-mail')
        !this.$v.email.required && errors.push('E-mail is required')
        return errors
    },
}

从“vuelidate”导入{validationMixin}
从“vuelidate/lib/validators”导入{required,email,…}
从“vuex”导入{mapActions};
导出默认值{
mixin:[验证mixin],
验证:{
...,
电子邮件:{必需,电子邮件},
...
},
数据:()=>({电子邮件:“”,…})
计算:{
电子邮件错误(){
常量错误=[]
如果(!this.$v.email.$dirty)返回错误
!this.$v.email.email&&errors.push('必须是有效的电子邮件')
!this.$v.email.required&&errors.push('需要电子邮件')
返回错误
},
}

在computed属性中,我已计算:{isDisabled:function(){return(this.fullname是否可以设置为禁用,直到用户输入有效的电子邮件?您想禁用什么?但是可以。为此,您只需使用computed
$v.$anydirty
(检查表单中的所有字段时,或使用
$v.email.$anydirty
检查值是否无效。您可以在组件的计算部分的Vue Devtools中检查值。我是否应该提供屏幕截图?