first
This commit is contained in:
48
node_modules/vant/es/mixins/portal.js
generated
vendored
Normal file
48
node_modules/vant/es/mixins/portal.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
function getElement(selector) {
|
||||
if (typeof selector === 'string') {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
|
||||
return selector();
|
||||
}
|
||||
|
||||
export function PortalMixin(_temp) {
|
||||
var _ref = _temp === void 0 ? {} : _temp,
|
||||
ref = _ref.ref,
|
||||
afterPortal = _ref.afterPortal;
|
||||
|
||||
return {
|
||||
props: {
|
||||
getContainer: [String, Function]
|
||||
},
|
||||
watch: {
|
||||
getContainer: 'portal'
|
||||
},
|
||||
mounted: function mounted() {
|
||||
if (this.getContainer) {
|
||||
this.portal();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
portal: function portal() {
|
||||
var getContainer = this.getContainer;
|
||||
var el = ref ? this.$refs[ref] : this.$el;
|
||||
var container;
|
||||
|
||||
if (getContainer) {
|
||||
container = getElement(getContainer);
|
||||
} else if (this.$parent) {
|
||||
container = this.$parent.$el;
|
||||
}
|
||||
|
||||
if (container && container !== el.parentNode) {
|
||||
container.appendChild(el);
|
||||
}
|
||||
|
||||
if (afterPortal) {
|
||||
afterPortal.call(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user