3***@qq.com
3***@qq.com
  • 发布:2024-04-13 16:13
  • 更新:2024-04-13 16:13
  • 阅读:591

uni-forms的校验数据方法validate()不生效

分类:uni-app
        <uni-forms :model="registerForm" :rules="rules" validateTrigger="bind" ref="registerForm" label-width="90px"  
            border>  
                    <!-- 顶部标题 -->  
                    <view>  
                        <uni-title type="h1" align="center" title="注册"></uni-title>  
                    </view>  

                    <!-- 昵称 -->  
                    <view>  
                        <uni-forms-item label='用户名:' name="userName" required>  
                            <uni-easyinput type="text" v-model="registerForm.userName" placeholder="请输入用户名"  
                                placeholderStyle="font-size: 16px;" />  
                        </uni-forms-item>  
                    </view>  
                        <!-- 提交表单 -->  
                        <button class="btn bg-blue flex-sub" hover-class="bg-gray" @click="validateData">注册</button>  

                    <!-- 密码设置 -->  
                    <view>  
                        <uni-forms-item label="密码:" name="password" required>  
                            <uni-easyinput type="password" v-model="registerForm.password" placeholder="请输入密码"  
                                placeholderStyle="font-size: 16px;" />  
                        </uni-forms-item>  
                    </view>  

                    <!-- 确认密码 -->  
                    <view>  
                        <uni-forms-item label="确认密码:" name="confirmPassword" required>  
                            <uni-easyinput type="password" v-model="registerForm.confirmPassword" placeholder="请确认密码"  
                                placeholder-style="font-size:16px" />  
                        </uni-forms-item>  
                    </view>  
        </uni-forms>

js代码
...
// 点击注册时,校验数据是否符合规范
validateData() {
this.$refs.registerForm.validate().then(res => {
console.log("表单校验成功");
}).catch(err => {
this.$modal.msgError("请填写正确信息");
console.log("表单校验失败:" + JSON.stringify(err));
})
},
问题描述:当我点击注册时,如果数据不符合规范,catch里面的内容是会输出的,但是数据符合规范的话,then里面的内容就不会触发,试了好多遍,还是这样

2024-04-13 16:13 负责人:无 分享
已邀请:

要回复问题请先登录注册