element plus 自定义表单控件触发校验

element plus

import { useFormItem } from 'element-plus';

const emit = defineEmits(['update:modelValue']);

const { formItem } = useFormItem(); // form formItem

const dynamicTags = computed({
	get() {
		return props.modelValue;
	},
	set(value) {
		emit('update:modelValue', value);
		formItem?.validate('blur'); // 触发校验
	}
});

element ui

this.$emit('change', value);
<el-input
	v-if="inputVisible"
	ref="InputRef"
	v-model="inputValue"
	class="ml-1 w-20"
	style="width: 80px"
	size="small"
	:validate-event="false" // 禁止v-model 变化 触发校验 
	v-bind="inputAttrs"
	@keyup.enter="handleInputConfirm"
	@blur="handleInputConfirm"
/>

版权声明:本文为Holly1945原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。