vue 封装全局的Loading

一、1.在app.vue组件注入loading样式

<template>
<meg-loading
    :tip="centitle"
    :indicator="indicator"
    :spinning="antLoading"
    style="background-color: rgba(0, 0, 0, 0.6)"
  >
  </meg-loading>
  </template>
  <script>
  import { mapState } from "vuex";
  export default {
  name: "MegCubeLayout",
    data() {
	 return {
  		indicator: <meg-icon name="megui-loading2"></meg-icon>,
	 };
  },
  computed: {
    ...mapState("megCube/container", ["antLoading", "centitle"]),
  		},
	  };

二、封装的js文件 globalMethod.js

export const showLoading = function (flag, msg) {
    if (msg) {
      this.$store.state.megCube.container.centitle = msg
    } else {
      this.$store.state.megCube.container.centitle = '加载中...'
    }
    if (flag) {
        this.$store.state.megCube.container.antLoading = flag
    } else {
        this.$store.state.megCube.container.antLoading = false

    }
    
  }

三、在main.js挂载

import { showLoading } from './common/globalMethod'
Vue.prototype.$showLoading = showLoading // 全局loading

四、vue页面调用

触发:	 this.$showLoading(true, '正在上传中')
停止:	 this.$showLoading(false)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值