Vue 自定义ElementUI的Loading效果

javascript 复制代码
import {  loadingText, messageDuration } from "@/settings";

import { Loading } from "element-ui";
// loadingText、messageDuration 这两个参数我是调的公共配置文件,按自己需求来 
const install = (Vue, opts = {}) => {

  /* 全局多彩Loading加载层 */
  Vue.prototype.$baseColorfullLoading = (index, text, callback) => {
    let loading;
    if (!index) {
      loading = Loading.service({
        lock: true,  // 是否锁屏
        text: text || loadingText, // 加载动画的文字
        spinner: "dots-loader",  // 引入的loading图标
        background: "hsla(0,0%,100%,.8)", // 背景颜色
      });
    } else {
      switch (index) {
        case 1:
          index = "dots";
          break;
        case 2:
          index = "gauge";
          break;
        case 3:
          index = "inner-circles";
          break;
        case 4:
          index = "plus";
          break;
      }
      loading = Loading.service({
        lock: true,  // 是否锁屏
        text: text || loadingText, // 加载动画的文字
        spinner: index + "-loader", // 引入的loading图标
        background: "hsla(0,0%,100%,.8)", // 背景颜色
        target: document.querySelector('.app-main-container'),  // **需要遮罩的区域
        // (我这里是指要求遮盖组件,如果你想全屏遮盖住,可以不要这行代码)
      });
    }
    if (callback) {
      callback(loading);
    } else {
      setTimeout(() => {
        loading.close();
      }, messageDuration);
    }
  };

};

if (typeof window !== "undefined" && window.Vue) {
  install(window.Vue);
}

export default install;

调用

javascript 复制代码
  // index可以填写1-4,4种效果
  this.$baseColorfullLoading(3)
相关推荐
勇敢di牛牛21 分钟前
vue3 + mars3D 三分钟画一个地球
前端·vue.js
我是日安2 小时前
从零到一打造 Vue3 响应式系统 Day 27 - toRef、toRefs、ProxyRef、unref
前端·javascript·vue.js
Q_Q19632884753 小时前
python+vue的在线租房 房屋租赁系统
开发语言·vue.js·spring boot·python·django·flask·node.js
不如喫茶去3 小时前
VUE查询-历史记录功能
前端·javascript·vue.js
武天3 小时前
说说你对slot的理解?slot使用场景有哪些?
vue.js
武天3 小时前
vue中,key的原理
vue.js
武天3 小时前
如何打破scope对样式隔离的限制?
vue.js
武天3 小时前
Vue中的$nextTick有什么作用?
vue.js
武天3 小时前
刷新浏览器后,Vuex的数据是否存在?如何解决?
vue.js
武天3 小时前
你是怎么处理vue项目中的错误的?
vue.js