The loading of Element Plus is loaded, and then the encapsulation directly called in js

I created a plugins folder in the src directory, and created a loading.js file in this folder.

The contents of the file are as follows:

import { ElLoading} from 'element-plus'
 
let loadingCount = 0;
let loading;
 
const startLoading = () => {
  loading = ElLoading.service({
    lock: true,
    text: '加载中……',
    background: 'rgba(0, 0, 0, 0.1)'
  });
};
 
const endLoading = () => {
  loading.close();
};
 
export const showLoading = () => {
  if (loadingCount === 0) {
    startLoading();
  }
  loadingCount += 1;
};
 
export const hideLoading = () => {
  if (loadingCount <= 0) {
    return;
  }
  loadingCount -= 1;
  if (loadingCount === 0) {
    endLoading();
  }
}

Where you need to load the effect, just introduce the method of this file, for example, another Hellow.vue page

import { showLoading, hideLoading } from '@/plugins/loading' //自封装loading加载效果引入



showLoading();//打开加载中

hideLoading();//关闭加载中
       

Guess you like

Origin blog.csdn.net/spring_007_999/article/details/130149532