diff --git a/src/dropdown-item/index.js b/src/dropdown-item/index.js
index e773666d0..f2f5d4afe 100644
--- a/src/dropdown-item/index.js
+++ b/src/dropdown-item/index.js
@@ -1,9 +1,10 @@
+import { Teleport } from 'vue';
+
// Utils
import { createNamespace } from '../utils';
import { on, off } from '../utils/dom/event';
// Mixins
-import { PortalMixin } from '../mixins/portal';
import { ChildrenMixin } from '../mixins/relation';
// Components
@@ -14,11 +15,12 @@ import Popup from '../popup';
const [createComponent, bem] = createNamespace('dropdown-item');
export default createComponent({
- mixins: [PortalMixin({ ref: 'wrapper' }), ChildrenMixin('vanDropdownMenu')],
+ mixins: [ChildrenMixin('vanDropdownMenu')],
props: {
title: String,
disabled: Boolean,
+ teleport: [String, Object],
modelValue: null,
titleClass: String,
options: {
@@ -150,38 +152,42 @@ export default createComponent({
style.bottom = `${offset}px`;
}
- return (
-
-
+
{
+ this.showWrapper = false;
+ this.$emit('closed');
+ }}
+ {...{ 'onUpdate:modelValue': this.onTogglePopup }}
>
- {
- this.showWrapper = false;
- this.$emit('closed');
- }}
- {...{ 'onUpdate:modelValue': this.onTogglePopup }}
- >
- {Options}
- {this.$slots.default?.()}
-
-
+ {Options}
+ {this.$slots.default?.()}
+
);
+
+ if (this.teleport) {
+ return {Content};
+ }
+
+ return Content;
},
});
diff --git a/src/mixins/portal.js b/src/mixins/portal.js
deleted file mode 100644
index 4d05b786f..000000000
--- a/src/mixins/portal.js
+++ /dev/null
@@ -1,47 +0,0 @@
-function getElement(teleport) {
- if (typeof teleport === 'string') {
- return document.querySelector(teleport);
- }
-
- return teleport;
-}
-
-export function PortalMixin({ ref, afterPortal } = {}) {
- return {
- props: {
- teleport: [String, Object],
- },
-
- watch: {
- teleport: 'portal',
- },
-
- mounted() {
- if (this.teleport) {
- this.portal();
- }
- },
-
- methods: {
- portal() {
- const { teleport } = this;
- const el = ref ? this.$refs[ref] : this.$el;
-
- let container;
- if (teleport) {
- container = getElement(teleport);
- } else if (this.$parent) {
- container = this.$parent.$el;
- }
-
- if (container && container !== el.parentNode) {
- container.appendChild(el);
- }
-
- if (afterPortal) {
- afterPortal.call(this);
- }
- },
- },
- };
-}