* 采用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;
}
},
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() {

View file

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