2023-07-18 14:00:50 +08:00

29 lines
983 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createApp } from "vue"
// 导入写好的Loading.vue文件
import Loading from "./loading.vue"
export default {
loading: null,
// 每当这个插件被添加到应用程序中时,如果它是一个对象,就会调用 install 方法。如果它是一个 function则函数本身将被调用。在这两种情况下——它都会收到两个参数由 Vue 的 createApp 生成的 app 对象和用户传入的选项。
install(app) {
if (this.loading) {
// 防止多次载入
app.config.globalProperties.$loading = this.loading
return
}
// 创建Loading实例用于挂载
let instance = createApp(Loading)
// 创建div元素装载Loading对象
let div = document.createElement("div")
div.setAttribute("id","maskbox")
let body = document.body
// 导入body中
body.appendChild(div);
this.loading = instance.mount(div)
// 挂载vue身上
app.config.globalProperties.$loading = this.loading;
}
}