icssoa 8 maanden geleden
bovenliggende
commit
b04cfb0066
2 gewijzigde bestanden met toevoegingen van 12 en 4 verwijderingen
  1. 1 1
      uni_modules/cool-ui/components/cl-input/cl-input.uvue
  2. 11 3
      uni_modules/cool-ui/hooks/form.ts

+ 1 - 1
uni_modules/cool-ui/components/cl-input/cl-input.uvue

@@ -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";

+ 11 - 3
uni_modules/cool-ui/hooks/form.ts

@@ -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);
 		});
 	}
 }