ant-design-vue/components/_util/portalDirective.js

25 lines
610 B
JavaScript
Raw Normal View History

2020-05-13 18:36:53 +08:00
export function antPortal(Vue) {
return Vue.directive('ant-portal', {
inserted(el, binding) {
const { value } = binding;
const parentNode = typeof value === 'function' ? value(el) : value;
if (parentNode !== el.parentNode) {
parentNode.appendChild(el);
}
},
componentUpdated(el, binding) {
const { value } = binding;
const parentNode = typeof value === 'function' ? value(el) : value;
if (parentNode !== el.parentNode) {
parentNode.appendChild(el);
}
},
});
}
export default {
install: Vue => {
antPortal(Vue);
},
};