From 4e31085656024415d21d3e4955ca3f590cde48fe Mon Sep 17 00:00:00 2001 From: BillyWang <181347204@qq.com> Date: Wed, 28 Mar 2018 22:42:16 +0800 Subject: [PATCH] * 采用inject方法,修正问题:当FormItem组件在slot里时,无法正确获取form组件 --- src/components/form/form-item.vue | 15 ++++++++------- src/components/form/form.vue | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/form/form-item.vue b/src/components/form/form-item.vue index 17fb988..1fc2019 100644 --- a/src/components/form/form-item.vue +++ b/src/components/form/form-item.vue @@ -92,6 +92,7 @@ this.validateState = val; } }, + inject: ['form'], computed: { classes () { return [ @@ -103,13 +104,13 @@ } ]; }, - form() { - let parent = this.$parent; - while (parent.$options.name !== 'iForm') { - parent = parent.$parent; - } - return parent; - }, + // form() { + // let parent = this.$parent; + // while (parent.$options.name !== 'iForm') { + // parent = parent.$parent; + // } + // return parent; + // }, fieldValue: { cache: false, get() { diff --git a/src/components/form/form.vue b/src/components/form/form.vue index 477b08f..57b284a 100644 --- a/src/components/form/form.vue +++ b/src/components/form/form.vue @@ -40,6 +40,9 @@ default: 'off' } }, + provide() { + return { form : this }; + }, data () { return { fields: [] -- libgit2 0.21.4