mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 05:29:01 +08:00
98 lines
2.3 KiB
Vue
98 lines
2.3 KiB
Vue
import PropTypes from './vue-types';
|
|
|
|
export default {
|
|
props: {
|
|
autoMount: PropTypes.bool.def(true),
|
|
autoDestroy: PropTypes.bool.def(true),
|
|
visible: PropTypes.bool,
|
|
forceRender: PropTypes.bool.def(false),
|
|
parent: PropTypes.any,
|
|
getComponent: PropTypes.func.isRequired,
|
|
getContainer: PropTypes.func.isRequired,
|
|
children: PropTypes.func.isRequired,
|
|
},
|
|
|
|
mounted() {
|
|
if (this.autoMount) {
|
|
this.renderComponent();
|
|
}
|
|
},
|
|
|
|
updated() {
|
|
if (this.autoMount) {
|
|
this.renderComponent();
|
|
}
|
|
},
|
|
|
|
beforeDestroy() {
|
|
if (this.autoDestroy) {
|
|
this.removeContainer();
|
|
}
|
|
},
|
|
methods: {
|
|
removeContainer() {
|
|
if (this.container) {
|
|
this._component && this._component.$destroy();
|
|
this.container.parentNode.removeChild(this.container);
|
|
this.container = null;
|
|
this._component = null;
|
|
}
|
|
},
|
|
|
|
renderComponent(props = {}, ready) {
|
|
const { visible, forceRender, getContainer, parent } = this;
|
|
const self = this;
|
|
if (visible || parent.$refs._component || forceRender) {
|
|
let el = this.componentEl;
|
|
if (!this.container) {
|
|
this.container = getContainer();
|
|
el = document.createElement('div');
|
|
this.componentEl = el;
|
|
this.container.appendChild(el);
|
|
}
|
|
if (!this._component) {
|
|
this._component = new this.$root.constructor({
|
|
el,
|
|
parent: self,
|
|
data: {
|
|
comProps: props,
|
|
},
|
|
mounted() {
|
|
this.$nextTick(() => {
|
|
if (ready) {
|
|
ready.call(self);
|
|
}
|
|
});
|
|
},
|
|
updated() {
|
|
this.$nextTick(() => {
|
|
if (ready) {
|
|
ready.call(self);
|
|
}
|
|
});
|
|
},
|
|
methods: {
|
|
forceRender(p) {
|
|
this.comProps = p;
|
|
this.$forceUpdate();
|
|
},
|
|
},
|
|
render() {
|
|
return self.getComponent(this.comProps);
|
|
},
|
|
});
|
|
} else {
|
|
this._component.forceRender(props);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
render() {
|
|
return this.children({
|
|
renderComponent: this.renderComponent,
|
|
removeContainer: this.removeContainer,
|
|
});
|
|
},
|
|
};
|