breaking change: rename get-container to teleport

This commit is contained in:
chenjiahan
2020-08-21 10:58:02 +08:00
parent 07d1a2590f
commit 52b187692b
39 changed files with 154 additions and 127 deletions
+10 -10
View File
@@ -1,35 +1,35 @@
function getElement(selector) {
if (typeof selector === 'string') {
return document.querySelector(selector);
function getElement(teleport) {
if (typeof teleport === 'string') {
return document.querySelector(teleport);
}
return selector();
return teleport;
}
export function PortalMixin({ ref, afterPortal } = {}) {
return {
props: {
getContainer: [String, Function],
teleport: [String, Object],
},
watch: {
getContainer: 'portal',
teleport: 'portal',
},
mounted() {
if (this.getContainer) {
if (this.teleport) {
this.portal();
}
},
methods: {
portal() {
const { getContainer } = this;
const { teleport } = this;
const el = ref ? this.$refs[ref] : this.$el;
let container;
if (getContainer) {
container = getElement(getContainer);
if (teleport) {
container = getElement(teleport);
} else if (this.$parent) {
container = this.$parent.$el;
}