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)
相关推荐
衫水3 分钟前
Ubuntu 系统部署 Vue/Vite 应用到 Nginx
vue.js·nginx·ubuntu
切糕师学AI8 分钟前
Vue 中的计算属性(computed)
前端·javascript·vue.js
程琬清君11 分钟前
Vue3DraggableResizable可移动范围有问题
前端·javascript·vue.js
天天开心a26 分钟前
Vue.js 基础教程笔记(一):Vue入门与环境搭建
前端·javascript·vue.js·笔记·前端框架
心.c39 分钟前
文件上传 - 入门篇
前端·javascript·vue.js·node.js·js
pas1361 小时前
33-mini-vue 更新element的children-双端对比diff算法
javascript·vue.js·算法
汝生淮南吾在北1 小时前
SpringBoot3+Vue3个人健康管理网站
vue.js·spring boot·毕业设计·毕设
靓仔建1 小时前
用tdesign-vue-next的t-tree-select做个下拉单选框
javascript·vue.js·tdesign
zhengxianyi51513 小时前
只需3句让Vue3 打包部署后通过修改配置文件修改全局变量——实时生效
vue.js·前后端分离·数据大屏·ruoyi-vue-pro优化
QQ40220549617 小时前
python基于vue的大学生课堂考勤系统设计与实现django flask pycharm
vue.js·python·django