3***@qq.com
3***@qq.com
  • 发布:2023-06-29 21:35
  • 更新:2023-07-04 14:38
  • 阅读:426

uni-forms校验有问题呀

分类:uni-app


点击提交,提示,然后输入框输入内容了,还提示

<template>  
    <view>  
        <uni-forms ref="form" :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="mobile">  
                <uni-easyinput type="text" v-model="formData.mobile" placeholder="请输入手机号" />  
            </uni-forms-item>  
            <uni-forms-item label="地址" name="address">  
                <uni-easyinput type="textarea" v-model="formData.address" placeholder="请输入详细地址" />  
            </uni-forms-item>  
        </uni-forms>  
        <button @click="submit">Submit</button>  
    </view>  
</template>  

<script setup>  
    import { onLoad } from '@dcloudio/uni-app'  
import { reactive, ref } from "vue";  
    const form = ref(null)  
    const formData = reactive({  
        name : "",  
        mobile : "",  
        address : ""  
    })  
    const rules = reactive({  
        name : {  
            rules : [{  
                required: true,  
                errorMessage: '收件人不能为空'  
            }]  
        }  
        mobile : {  
            rules : [  
                {  
                    required: true,  
                    errorMessage: '手机号不能为空'  
                },  
                {  
                    format: 'number',  
                    errorMessage: '只能输入数字'  
                }  
            ]  
        },  
        address : {  
            rules : [{  
                required: true,  
                errorMessage: '地址不能为空'  
            }]  
        }  
    })  

    //接受上个页面传递过来的参数  
    onLoad(function (option) {  
        console.log(option)  
    })  

    function submit () {  
        form.value.validate().then(res => {  
            console.log('success', res);  
            uni.showToast({  
                title: `校验通过`  
            })  
        }).catch(err => {  
            console.log('err', err);  
        })  
        console.log(form.value)  
    }  
</script>
2023-06-29 21:35 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com

uni-forms没有绑定formdata,兄弟

<uni-forms ref="form" :rules="rules" :model="formData">
</uni-forms>

onion一只洋葱

onion一只洋葱 - 一只前端

:modelValue="formData"

绑一下

Diligent_UI

Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序

uni-form既要绑定form对象也需要绑定rules

要回复问题请先登录注册