1***@qq.com
1***@qq.com
  • 发布:2024-11-23 15:21
  • 更新:2024-12-09 13:09
  • 阅读:139

使用validate 表单验证在验证后没有后续是什么问题

2024-11-23 15:21 负责人:无 分享
已邀请:
ijiangruyi

ijiangruyi - mind.lingyun.net

什么叫没有后续?可以看下演示代码的表单验证。

  • apche

    uFormRef.value.validate() 返回 undefined

    2024-11-27 10:48

apche

apche

<up-form :model="form" ref="uFormRef">
<up-form-item label="姓名" prop="name">
<up-input v-model="form.name" />
</up-form-item>
</up-form>
<up-button @click="submit">提交</up-button>

const form = ref({    
  name: '',    
});    

// 校验规则    

// 表单引用    
const uFormRef = ref(null);    

// 提交方法    
function submit() {    
  uFormRef.value.validate().then(valid => {    
    if (valid) {    
      uni.showToast({  
        icon:'none',  
        title:"ddd"  
      })  
    } else {    
      uni.showToast({  
        icon:'none',  
                title:"222"  
      })  
    }    
  }).catch(() => {    
    // 处理验证错误    
    uni.showToast({  
        icon:'none',  
                title:"55555"  
    })  
  });    
}
  • apche

    应该是规则没生效

    2024-11-27 11:36

relax

relax

我也遇到了,我的代码

<template>  
    <view>  
        <up-form :model="member" ref="mFormRef" :rules="rules">  
            <up-form-item label="账号" prop="account" :required="true">  
                <up-input v-model="member.account" />  
            </up-form-item>  
            <up-form-item label="密码" prop="pwd" :required="true">  
                <up-input :password="true" v-model="member.pwd"></up-input>  
            </up-form-item>  
        </up-form>  
        <up-button @click="submit">提交</up-button>  
    </view>  
</template>  
<script setup lang="ts">  
    import { reactive, ref } from 'vue';  
    const member = reactive({});  
    const mFormRef = ref();  
    const rules = {  
        account: [  
            {  
                required: true,  
                message: '请输入账号',  
                trigger: ['blur']  
            }  
        ],  
        pwd: [  
            {  
                required: true,  
                message: '请输入密码',  
                trigger: ['blur']  
            }  
        ],  
    }  
    function submit() {  
        mFormRef.value.validate().then((valid) => {  
            if (valid) {  
                uni.showToast({ title: "成功" })  
            }  
        }).catch(() => {  
            console.log("errorxx");  
        });  
    }  
</script>  
<style>  
</style>

要回复问题请先登录注册