index.js
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Vue from 'vue'
import Popup from './index.vue'
const PopupBox = Vue.extend(Popup)
let popuping = undefined
PopupBox.prototype.close = function () {
// 如果Popup 有引用,则去掉引用
if (popuping) {
popuping = undefined
}
// 先将组件隐藏
this.isShow = false
// 延迟300毫秒,等待Popup关闭动画执行完之后销毁组件
setTimeout(() => {
// 移除挂载的dom元素
if (this.$el && this.$el.parentNode) {
this.$el.parentNode.removeChild(this.$el)
}
}, 300)
}
const Popup1 = (title, editItem, data, formData) => {
// 如果组件已渲染,则返回即可
if (popuping) {
return popuping
}
data.title = title
data.editItem = editItem
if (formData) {
data.formData = formData
}
// 通过构造函数初始化组件 相当于 new Vue()
let instance = new PopupBox({
data
}).$mount()
document.body.appendChild(instance.$el)
Vue.nextTick(() => {
instance.isShow = true
})
// 将组件实例赋值给loading
popuping = instance
return instance
}
export default Popup1