perf: update formItem give some tip
parent
cf81f54a96
commit
beef6c6662
|
@ -66,23 +66,17 @@ export default {
|
||||||
decoratorFormProps: { default: () => ({}) },
|
decoratorFormProps: { default: () => ({}) },
|
||||||
collectFormItemContext: { default: () => noop },
|
collectFormItemContext: { default: () => noop },
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
this.collectContext();
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
const { templateContext = {} } = this.FormProps.form || {};
|
|
||||||
const vnodes = Object.values(templateContext.$slots || {}).reduce((a, b) => {
|
|
||||||
return [...a, ...b];
|
|
||||||
}, []);
|
|
||||||
const isSlot = comeFromSlot(vnodes, this.$vnode);
|
|
||||||
warning(!isSlot, 'You can not set FormItem from slot, please use slot-scope instead slot');
|
|
||||||
let isSlotScope = false;
|
|
||||||
// 进一步判断是否是通过slot-scope传递
|
|
||||||
if (!isSlot && this.$vnode.context !== templateContext) {
|
|
||||||
isSlotScope = comeFromSlot(this.$vnode.context.$children, templateContext.$vnode);
|
|
||||||
}
|
|
||||||
if (!isSlotScope && !isSlot) {
|
|
||||||
this.collectFormItemContext(this.$vnode.context);
|
|
||||||
}
|
|
||||||
return { helpShow: false };
|
return { helpShow: false };
|
||||||
},
|
},
|
||||||
|
beforeUpdate() {
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
this.collectContext();
|
||||||
|
}
|
||||||
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.collectFormItemContext(this.$vnode.context, 'delete');
|
this.collectFormItemContext(this.$vnode.context, 'delete');
|
||||||
},
|
},
|
||||||
|
@ -98,6 +92,24 @@ export default {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
collectContext() {
|
||||||
|
if (this.FormProps.form && this.FormProps.form.templateContext) {
|
||||||
|
const { templateContext } = this.FormProps.form;
|
||||||
|
const vnodes = Object.values(templateContext.$slots || {}).reduce((a, b) => {
|
||||||
|
return [...a, ...b];
|
||||||
|
}, []);
|
||||||
|
const isSlot = comeFromSlot(vnodes, this.$vnode);
|
||||||
|
warning(!isSlot, 'You can not set FormItem from slot, please use slot-scope instead slot');
|
||||||
|
let isSlotScope = false;
|
||||||
|
// 进一步判断是否是通过slot-scope传递
|
||||||
|
if (!isSlot && this.$vnode.context !== templateContext) {
|
||||||
|
isSlotScope = comeFromSlot(this.$vnode.context.$children, templateContext.$vnode);
|
||||||
|
}
|
||||||
|
if (!isSlotScope && !isSlot) {
|
||||||
|
this.collectFormItemContext(this.$vnode.context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
getHelpMessage() {
|
getHelpMessage() {
|
||||||
const help = getComponentFromProp(this, 'help');
|
const help = getComponentFromProp(this, 'help');
|
||||||
const onlyControl = this.getOnlyControl();
|
const onlyControl = this.getOnlyControl();
|
||||||
|
|
Loading…
Reference in New Issue