* 采用inject方法,修正问题:当FormItem组件在slot里时,无法正确获取form组件

This commit is contained in:
BillyWang 2018-03-28 22:42:16 +08:00
parent d45d2ee061
commit 4e31085656
2 changed files with 11 additions and 7 deletions

View file

@ -92,6 +92,7 @@
this.validateState = val; this.validateState = val;
} }
}, },
inject: ['form'],
computed: { computed: {
classes () { classes () {
return [ return [
@ -103,13 +104,13 @@
} }
]; ];
}, },
form() { // form() {
let parent = this.$parent; // let parent = this.$parent;
while (parent.$options.name !== 'iForm') { // while (parent.$options.name !== 'iForm') {
parent = parent.$parent; // parent = parent.$parent;
} // }
return parent; // return parent;
}, // },
fieldValue: { fieldValue: {
cache: false, cache: false,
get() { get() {

View file

@ -40,6 +40,9 @@
default: 'off' default: 'off'
} }
}, },
provide() {
return { form : this };
},
data () { data () {
return { return {
fields: [] fields: []