This commit is contained in:
icssoa
2025-08-12 14:30:20 +08:00
parent 93be8d8b5d
commit b04cfb0066
2 changed files with 12 additions and 4 deletions

View File

@@ -81,7 +81,7 @@
</template>
<script setup lang="ts">
import { computed, nextTick, onMounted, ref, watch, type PropType } from "vue";
import { computed, nextTick, ref, watch, type PropType } from "vue";
import type { ClInputType, PassThroughProps } from "../../types";
import { isDark, parseClass, parsePt } from "@/cool";
import type { ClIconProps } from "../cl-icon/props";

View File

@@ -93,19 +93,27 @@ export class Form {
}
class FormItem {
public formItemRef = ref<ClFormItemComponentPublicInstance | null>(null);
public isError: ComputedRef<boolean>;
constructor() {
const { isError } = new Form();
const ClFormItem = useParent<ClFormItemComponentPublicInstance>("cl-form-item");
if (this.formItemRef.value == null) {
const ClFormItem = useParent<ClFormItemComponentPublicInstance>("cl-form-item");
if (ClFormItem != null) {
this.formItemRef.value = ClFormItem;
}
}
// 监听表单字段是否验证错误
this.isError = computed<boolean>(() => {
if (ClFormItem == null) {
if (this.formItemRef.value == null) {
return false;
}
return isError(ClFormItem.prop);
return isError(this.formItemRef.value.prop);
});
}
}