UNPKG

@prettyy/ui

Version:

vue2 UI

48 lines (40 loc) 965 B
import Vue from "vue" import loadingVue from "./main.vue" import afterLeave from "../../../utils/after-leave" const LoadingConstructor = Vue.extend(loadingVue) LoadingConstructor.prototype.close = function () { afterLeave( this, () => { if (this.$el && this.$el.parentNode) { this.$el.parentNode.removeChild(this.$el) } this.$destroy() }, 300 ) this.visible = false } const Loading = function (options = {}) { if (typeof options === 'string') { options = { text: options } } // 初始化 const instance = new LoadingConstructor({ data: options, }) // 实例组件挂载 instance.$mount() if (options.el) { document.querySelector(options.el).appendChild(instance.$el) } else { document.body.appendChild(instance.$el) } Vue.nextTick(() => { instance.visible = true }) return instance } export default Loading