【uniapp学习之】uni-forms必填项校验

代码块

<uni-forms ref="baseForm" :modelValue="baseFormData" label-width='auto' :rules="rules">
	<uni-forms-item label="企业名称" required name="principalName">
		<uni-easyinput v-model="baseFormData.principalName" placeholder="请输入企业名称" />
	</uni-forms-item>
</uni-forms>

data(){
	return{
		rules: {
			principalName: {
				rules: [{
						required: true,
						errorMessage: ' ',
					},
				],
			},
		}
	}
}

buttonClick(e) {
	this.$refs.baseForm.validate().then(res=>{
		console.log('表单数据信息:', res);
	}).catch(err =>{
		console.log('表单错误信息:', err);
	})
}

效果图

【uniapp学习之】uni-forms必填项校验_第1张图片

你可能感兴趣的:(uni-app,学习,javascript)