有没有人遇到过图中的问题,uniapp使用uniforms做表单校验的时候,校验信息闪了一下就消失了,找了很多办法还没解决,不知道哪里的问题。

代码如下⬇️
<template>
<view class="container">
<uni-forms
ref="formRef"
:modelValue="formData"
label-align="right"
label-width="200rpx"
:rules="rules"
validate-trigger="bind"
>
<uni-forms-item label="小说名称:" required name="name">
<!-- <view class="input_class">
<input type="text" v-model="formData.name"/>
</view> -->
<uni-easyinput v-model="formData.name"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="小说链接:" required name="novelUrl">
<!-- <view class="input_class">
<input type="text" v-model="formData.novelUrl"/>
</view> -->
<uni-easyinput v-model="formData.novelUrl"></uni-easyinput>
</uni-forms-item>
</uni-forms>
<view class="btn_footer">
<BtnVue text="提交" width="500rpx" height="100rpx" bgc="rgb(66, 165, 245)" @click="submit"></BtnVue>
</view>
</view>
</template>
<script setup lang="uts">
const formRef = ref()
const formData = ref({
name: '',
novelUrl: ''
})
const rules = {// 小说名称的校验规则
name: {
rules: [
{
required: true,
errorMessage: '请输入小说名',
}
]
},
// 小说链接的校验规则
novelUrl: {
rules: [
{
required: true,
errorMessage: '请输入小说链接',
}
]
}
}
const submit = () => {
formRef.value.validate().then(() => {
console.log('校验通过,可以提交数据')
// 这里写提交到服务器的逻辑
}).catch(errors => {
console.log('校验失败', errors)
})
}
onReady(() => {
// 可以使用:rules="rules",也可有使用下面的方式
// formRef.value.setRules(rules)
})
</script>
<style lang="less" scoped>
.container {
padding: 20rpx;
height: 100%;
.input_class {
background-color: #efefef;
border-radius: 10px;
border: 1px solid beige;
display: flex;
align-items: center;
width: 100%;
height: 100%;
}
.btn_footer {
position: absolute;
bottom: calc(10rpx + env(safe-area-inset-bottom));
left: 50%;
transform: translate(-50%);
}
}
</style>