q***@163.com
q***@163.com
  • 发布:2021-09-02 16:50
  • 更新:2021-09-02 17:06
  • 阅读:411

#插件讨论# 【 uni-forms 表单 - DCloud前端团队 】uni-forms 校验的问题

分类:uni-app

问题:复制的demo ,默认空值,直接提交验证成功 值为undefined

<template>  
    <view class="content">  
        <uni-forms ref="form" :modelValue="formData" :rules="rules">  
                    <uni-forms-item label="姓名" name="name">  
                        <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />  
                    </uni-forms-item>  
                    <uni-forms-item label="邮箱" name="email">  
                        <input class="input" v-model="formData.email" type="text" placeholder="请输入邮箱" @input="binddata('email',$event.detail.value)" />  
                    </uni-forms-item>  
                </uni-forms>  
        <button @click="submit">Submit</button>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                formData: {  
                    name: '',  
                    email: ''  
                },  
                rules: {  
                    // 对name字段进行必填验证  
                    name: {  
                        rules: [{  
                                required: true,  
                                errorMessage: '请输入姓名',  
                            },  
                            {  
                                minLength: 3,  
                                maxLength: 5,  
                                errorMessage: '姓名长度在 {minLength} 到 {maxLength} 个字符',  
                            }  
                        ]  
                    },  
                    // 对email字段进行必填验证  
                    email: {  
                        rules: [{  
                            format: 'email',  
                            errorMessage: '请输入正确的邮箱地址',  
                        }]  
                    }  
                }  
            }  
        },  
        onLoad() {  

        },  
        methods: {  
            submit() {  
                this.$refs.form.validate().then(res=>{  
                    console.log("formdata",this.formData)  
                    console.log('验证成功数据信息:', res);    
                }).catch(err =>{  
                    console.log('表单错误信息:', err);  
                })  
            },  
        }  
    }  
</script>  
<style scoped lang="scss">  
</style>  
2021-09-02 16:50 负责人:无 分享
已邀请:
1***@163.com

1***@163.com

咯不

该问题目前已经被锁定, 无法添加新回复