Element-ui 全局设置loading

隐身守侯 提交于 2019-11-30 17:39:23

main.js

 

import { Loading } from 'element-ui';

 


let loadingCount = 0;
let loading;

const startLoading = () => {
  loading = Loading.service({
    lock: true,
    text: '加载中……',
    background: 'rgba(0, 0, 0, 0.7)'
  });
};

const endLoading = () => {
  loading.close();
};

const showLoading = () => {
  if (loadingCount === 0) {
    startLoading();
  }
  loadingCount += 1;
};

const hideLoading = () => {
  if (loadingCount <= 0) {
    return;
  }
  loadingCount -= 1;
  if (loadingCount === 0) {
    endLoading();
  }
};

 

.....

 

Vue.prototype.request = function(json, callback, url, callbackData) {
     ....

      showLoading();
      axios({
        method: 'post',
        url: url,
        data: requeData,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
      }).then(function(res) { 
        hideLoading();
        ......

      })
    }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!