首页 > 其他分享 >vue.js3:用el-loading显示加载动画([email protected] / [email protected])

vue.js3:用el-loading显示加载动画([email protected] / [email protected])

时间:2022-10-08 17:36:01浏览次数:75  
标签:el vue 37 element loading plus 3.2 data

一,el-loading

1,文档地址:

https://element-plus.gitee.io/zh-CN/component/loading.html

2,  查看element-plus的版本:

liuhongdi@lhdpc:/data/vue/imgtouch$ npm list element-plus
[email protected] /data/vue/imgtouch
└── [email protected]

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: [email protected]

二,js代码:

1,封装类:

import { ElLoading } from 'element-plus';

// 定义请求次数的变量,记录当前页面总共请求的次数
let loadingRequestCount = 0;
// 初始化loading
let loadingInstance;

//显示loading的函数 并且记录请求次数 ++
const showLoading = () => {
    if (loadingRequestCount === 0) {
        //ElLoading.
        loadingInstance = ElLoading.service({
            //color:'#ff0000',
            fullscreen:true,
            lock:true,
            text:'加载中...',
            //spinner:'el-icon-loading',
            //customClass:'lb-loading-icon-cls',
            background:'rgba(0, 0, 0, 0.3)'
        });
    }
    loadingRequestCount++
}

//隐藏loading的函数,并且记录请求次数 --
const hideLoading = () => {
    if (loadingRequestCount <= 0) return
    loadingRequestCount--
    if (loadingRequestCount === 0) {
        loadingInstance.close();
    }
}

export {
    showLoading,
    hideLoading
}

2,调用

<template>
<div>
  <div style="width:800px;margin: auto;display: flex;flex-direction: column;">
  <div>
    <input type="button" value="得到用户信息" @click="getUserInfo" />
  </div>
</div>
</div>
</template>

<script>
import axios from 'axios'
import { showLoading, hideLoading } from '@/utils/loading'

export default {
  name: "LoadingComp",
  setup() {
    //获取用户信息
    const getUserInfo = () => {
      showLoading();
      let url = "/api/home/home";
      let getData = {
        msg:'hello',
      };
      axios({
        method:"get",
        url:url,
        params:getData,
      }).then((res) => {
            hideLoading();
            console.log(res.data);
            if (res.data.code == 0) {
              let data = res.data.data;
              alert("success:content:"+data.content);
            } else {
              alert("error:"+res.data.msg);
            }
          }
      ).catch(err=>{
        hideLoading();
        console.log(err);
        alert('网络错误:'+err.message);
      });
    }

    return {
      getUserInfo,
    }
  }
}
</script>

<style scoped>
</style>

三,测试效果

四,查看vue框架的版本:

root@lhdpc:/data/vue/axios# npm list vue
[email protected] /data/vue/axios
├─┬ @vue/[email protected]
│ └─┬ @vue/[email protected]
│   └── [email protected] deduped
└─┬ [email protected]
  └─┬ @vue/[email protected]
    └── [email protected] deduped

 

标签:el,vue,37,element,loading,plus,3.2,data
From: https://www.cnblogs.com/architectforest/p/16769618.html

相关文章

  • vue路由加载页面
    当vue路由切换时,有时候会出现短暂白屏,需要添加一个加载状态参考:buildadmin地址:https://demo.buildadmin.com/#/利用vue的路由导航守卫:beforeEach、afterEach来判断显示......
  • 【Vue3.x】pinia
    PiniaVue3中使用Pinia替代vuex更改如下:支持ts体积小,压缩后1KB去除mutations,只有state,getters,actions;去除mutations后,actions直接进行同步和异步操作修改数据去......
  • vue-2 模板语法
    router/index.js//1、引入基础依赖importVuefrom'vue'importRouterfrom'vue-router'//2、引入要路由的页面importSmartyfrom"../components/smarty"//3、......
  • vue的computed计算属性的执行机制
    vue中初始化computed,每一个计算属性的本质就是watcher,创建计算属性的watcher的时候,会传入一个懒惰属性,来控制computed缓存,默认是执行的,先处理为vm._computedWatchers对象......
  • NETCORE - ElasticSearch 搜索服务
                                            引用:https://www.cnblogs.com/qiect/arti......
  • vuecli build 代码拆解
    splitChunks:{//表示选择哪些chunks进行分割,可选值有:async,initial和allchunks:"async",//表示新分离出的chunk必须大于等于minSize,默认为30000,约3......
  • 表格排重 | EXCEL表格数据排重,使用相同颜色标记相同值
    前言日常工作处理EXCEL表格数据,通常需要快速查找出表格中重复的数据项,并标注颜色,通过颜色区分数据。此外,使用小O地图EXCEL插件进行地图可视化时,需要将相同数值的数据设置......
  • vuex中commit
    一、不使用模块的基础模式看vuex相关的文件夹,放在src下的store文件夹,里面有一个index.js文件,为vuex的入口,如果不使用模块,可以将所有相关代码写在index.js文件里面,下面是最......
  • shell 运算符
    shell中的比较运算符:-eq    //等于-ne    //不等于-gt    //大于(greater)-lt     //小于 (less)-ge    //大于等于-le  ......
  • 重装Intel核显后,设备管理器英特尔显卡属性这里报告了一个未启动设备(igfx)
    问题:卸载了Intel集显之后,重装,发现外接显示器无法被识别并显示页面在设备管理器里面,右键核显的属性,查看事件,显示“未启动设备(igfx)”解决方案:右键集显,点击“扫描硬件改动”......