ant-design-vue/components/_util/Portal.tsx
tangjinzhou a5a3411c28
refactor: drawer (#4725)
* refactor(drawer): use compositionAPI

* refactor(drawer): update

* refactor: update

* chore: update

* docs: update

* fix: remove transitionStr

* chore: use useConfigInject

* refactor: drawer #4708

Co-authored-by: ajuner <106791576@qq.com>
2021-10-03 13:30:50 +08:00

30 lines
777 B
Vue

import PropTypes from './vue-types';
import { defineComponent, nextTick, onBeforeUnmount, onUpdated, Teleport } from 'vue';
export default defineComponent({
name: 'Portal',
inheritAttrs: false,
props: {
getContainer: PropTypes.func.isRequired,
didUpdate: PropTypes.func,
},
setup(props, { slots }) {
// getContainer 不会改变,不用响应式
const container = props.getContainer();
onUpdated(() => {
nextTick(() => {
props.didUpdate?.(props);
});
});
onBeforeUnmount(() => {
if (container && container.parentNode) {
container.parentNode.removeChild(container);
}
});
return () => {
return container ? <Teleport to={container} v-slots={slots}></Teleport> : null;
};
},
});