问题:复制的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>
1 个回复
1***@163.com
咯不