1
0
Fork 0
5g-track/src/globalComponents/Loading/index.js

34 lines
1.3 KiB
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 LoadingComponent from './loading.vue'
const Loading = {};
// 注册Loading
Loading.install = function (Vue) {
// 生成一个Vue的子类
// 同时这个子类也就是组件
const LoadingConstructor = Vue.extend(LoadingComponent);
// 生成一个该子类的实例
const instance = new LoadingConstructor();
// 将这个实例挂载在我创建的div上
instance.$mount(document.createElement('div'));
// 并将此div加入全局挂载点内部
document.body.appendChild(instance.$el);
// 通过Vue的原型注册一个方法
// 让所有实例共享这个方法
function handlerloading(text = '', full) {
instance.text = text; //文字是以最后一个show的展示
instance.full = true; //控制填充满屏,但不开放使用;
}
const loading_main = {
show(text = ''){
instance.loadings.push('show') //执行一次添加一个
handlerloading(text) //把text填充
},
hidden(){
instance.loadings.pop() //执行一次减少一个通过数组长度控制显示与否考虑到同时打开多个loading情况
}
}
//将方法挂载全局
Vue.prototype.$Loading = loading_main;
}
export default Loading