使用validate 表单验证在验证后没有后续是什么问题
1***@qq.com
- 发布:2024-11-23 15:21
- 更新:2024-12-09 13:09
- 阅读:139
<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"
})
});
}
我也遇到了,我的代码
<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>
apche
uFormRef.value.validate() 返回 undefined
2024-11-27 10:48