فهرست منبع

修复jsx中使用getFieldDecorator报错Cannot read property 'value' of undefined

xwlyy 5 سال پیش
والد
کامیت
abfdc06e7b
2فایلهای تغییر یافته به همراه21 افزوده شده و 21 حذف شده
  1. 1 21
      src/components/Login/LoginItem.vue
  2. 20 0
      src/main.js

+ 1 - 21
src/components/Login/LoginItem.vue

@@ -4,27 +4,7 @@ import omit from "lodash/omit";
 import LoginContext from "./LoginContext";
 import ItemMap from "./map";
 
-// const FormItem = Form.Item;
-
-// FormItem中的decoratorOption方法有bug,已提交pr到ant-design-vue
-// 11行到27行为临时解决方案
-import cloneDeep from "lodash/cloneDeep";
-import warning from "ant-design-vue/es/_util/warning";
-const FormItem = cloneDeep(Form.Item);
-FormItem.methods.decoratorOption = vnode => {
-  if (vnode.data && vnode.data.directives) {
-    const directive = find(vnode.data.directives, ["name", "decorator"]);
-    warning(
-      !directive || (directive && Array.isArray(directive.value)),
-      `Invalid directive: type check failed for directive "decorator". Expected Array, got ${typeof (directive // directive可能为undefined
-        ? directive.value
-        : directive)}. At ${vnode.tag}.`
-    );
-    return directive ? directive.value : null;
-  } else {
-    return null;
-  }
-};
+const FormItem = Form.Item;
 
 const WrapFormItem = {
   data() {

+ 20 - 0
src/main.js

@@ -42,6 +42,26 @@ import "highlight.js/styles/github.css";
 import ref from "vue-ref";
 Vue.use(ref, { name: "ant-ref" });
 
+// FormItem中的decoratorOption方法有bug,已提交pr到ant-design-vue
+// 47行到73行为临时解决方案
+const FormItem = Form.Item;
+import find from "lodash/find";
+import warning from "ant-design-vue/es/_util/warning";
+FormItem.methods.decoratorOption = vnode => {
+  if (vnode.data && vnode.data.directives) {
+    const directive = find(vnode.data.directives, ["name", "decorator"]);
+    warning(
+      !directive || (directive && Array.isArray(directive.value)),
+      `Invalid directive: type check failed for directive "decorator". Expected Array, got ${typeof (directive // directive可能为undefined
+        ? directive.value
+        : directive)}. At ${vnode.tag}.`
+    );
+    return directive ? directive.value : null;
+  } else {
+    return null;
+  }
+};
+
 Vue.config.productionTip = false;
 
 Vue.use(Button);