上图不上种,菊花万人捅:

loading.js:

import './loading.css'

let Loading = {}
// 避免重复install,设立flag
Loading.installed = false
Loading.install = function (Vue) {
if (Loading.installed) return
Vue.prototype.$loading = {}
Vue.prototype.$loading.show = () => {
// 如果页面有loading则不继续执行
if (document.querySelector('#vue-loading')) return
// 1、创建构造器,定义loading模板
let LoadingTip = Vue.extend({
template: `<div id="vue-loading">
<div class="loader"></div>
</div>`
})
// 2、创建实例,挂载到文档以后的地方
let tpl = new LoadingTip().$mount().$el
// 3、把创建的实例添加到body中
document.body.appendChild(tpl)
// 阻止遮罩滑动
document.querySelector('#vue-loading').addEventListener('touchmove', function (e) {
e.stopPropagation()
e.preventDefault()
})
Loading.installed = true
}
Vue.prototype.$loading.hide = () => {
let tpl = document.querySelector('#vue-loading')
document.body.removeChild(tpl)
}
} export default Loading

  loading.css:

#vue-loading {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0
} .loader {
position: relative;
width: 2.5em;
height: 2.5em;
transform: rotate(165deg);
} .loader:before, .loader:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
display: block;
width: 0.5em;
height: 0.5em;
border-radius: 0.25em;
transform: translate(-50%, -50%);
} .loader:before {
animation: before 2s infinite;
} .loader:after {
animation: after 2s infinite;
} @keyframes before {
0% {
width: 0.5em;
box-shadow: 1em -0.5em rgba(225, 20, 98, 0.75), -1em 0.5em rgba(111, 202, 220, 0.75);
}
35% {
width: 2.5em;
box-shadow: 0 -0.5em rgba(225, 20, 98, 0.75), 0 0.5em rgba(111, 202, 220, 0.75);
}
70% {
width: 0.5em;
box-shadow: -1em -0.5em rgba(225, 20, 98, 0.75), 1em 0.5em rgba(111, 202, 220, 0.75);
}
100% {
box-shadow: 1em -0.5em rgba(225, 20, 98, 0.75), -1em 0.5em rgba(111, 202, 220, 0.75);
}
} @keyframes after {
0% {
height: 0.5em;
box-shadow: 0.5em 1em rgba(61, 184, 143, 0.75), -0.5em -1em rgba(233, 169, 32, 0.75);
}
35% {
height: 2.5em;
box-shadow: 0.5em 0 rgba(61, 184, 143, 0.75), -0.5em 0 rgba(233, 169, 32, 0.75);
}
70% {
height: 0.5em;
box-shadow: 0.5em -1em rgba(61, 184, 143, 0.75), -0.5em 1em rgba(233, 169, 32, 0.75);
}
100% {
box-shadow: 0.5em 1em rgba(61, 184, 143, 0.75), -0.5em -1em rgba(233, 169, 32, 0.75);
}
} /**
* Attempt to center the whole thing!
*/
html,
body {
height: 100%;
} .loader {
position: absolute;
top: calc(50% - 1.25em);
left: calc(50% - 1.25em);
}

  在main.js里面 :

   import Vue from 'vue';
   import Loading from '@/components/loading'
   Vue.use(Loading)

  这样就可以直接在组件里面手动调用啦!

  调用方法: this.$loading.show(),  this.$loading.hide()

  因为这个项目暂时规模很小,就只有注册功能,我直接把调用写在axios请求拦截器里面,每次请求和请求结束都会调用loading,这样就不用在页面里面手动调用啦。

[vue开发记录]全局loading组件的更多相关文章

  1. 基于Vue开发的tab切换组件

    github地址:https://github.com/MengFangui/VueTabSwitch 1.index.html <!DOCTYPE html> <html lang ...

  2. vue开发记录--element-ui的form表单label和placeholder国际化遇到的小问题

    <el-form-item label="$t('permission.employeeName')"> <el-input v-model="form ...

  3. vue全局loading组件

    本组件作用在页面加载完成前进行loader提示,提升用户体验,只需要在app.vue中引用一次,整个项目中路由切换时就可以自动进行提示(vuex版): 1. 添加vuex值和方法: import Vu ...

  4. [vue开发记录]vue仿ios原生datepicker实现

    先上个效果图 现在只开发了年月,还在优化. 在网上看了一个纯原生js实现实现惯性滚动和回弹的文章  地址:https://www.cnblogs.com/ranyonsue/p/8119155.htm ...

  5. vue开发记录

    vue开发过程中遇到的一些小问题.小技巧等,会不断更新~ 记录不详细处,欢迎留言

  6. vue和element全局loading

    http请求的代码如下: import axios from 'axios' import { Message} from 'element-ui' import store from '../sto ...

  7. [vue开发记录]float label输入框

    上图: 组件代码: <!-- Created by Locke Ou on 2018/6/20. --> <template> <div> <div clas ...

  8. Cocos2d-js 开发记录:Loading载入界面自定义

    Loading界面是一个cc.Scene具体请看: http://blog.csdn.net/jonahzheng/article/details/38348255 如果仅仅是想把图片(cocos l ...

  9. CCS+C6678LE开发记录12:UIA组件的安装

    在安装了CCS 6.0版本的IDE和最新版的MCSDK后似乎一切都很完美,但事实并非如此. 当我试图编译SDK附带的image_processing (IPC based) demo时出现如下错误: ...

随机推荐

  1. 【easy】110. Balanced Binary Tree判断二叉树是否平衡

    判断二叉树是否平衡 a height-balanced binary tree is defined as a binary tree in which the depth of the two su ...

  2. Easy RM to MP3 Converter栈溢出定位及漏洞利用

    本文主要是Easy RM to MP3 Converter(MFC++编写)栈溢出的定位及windows下shellcode编写的一些心得. 用到的工具及漏洞程序下载地址https://github. ...

  3. 【原创】大叔问题定位分享(24)hbase standalone方式启动报错

    hbase 2.0.2 hbase standalone方式启动报错: 2019-01-17 15:49:08,730 ERROR [Thread-24] master.HMaster: Failed ...

  4. git用代码库文件完全覆盖本地/git不能提交jar的设置

    用代码库中的文件完全覆盖本地工作版本. 方法如下: git reset --hard git pull 操作后 本地该目录下所有修改都会被删除!!! 谨慎操作! 项目目录下 文件:.gitignore ...

  5. 根据token分割字串

    #include <iostream> #include <string> #include <cstring> int main() { const char * ...

  6. 课堂小记---JavaScript(1)

    day01 1.数据类型  number string boolean undefined object function 加号具有两种功能,数字相加 和 字符串拼接.加号两边只要碰见字符串,则执行字 ...

  7. 1、python基础

    本节主要内容 语言特性 变量 注释 字符串拼接 循环 数据类型与字符编码 三元运算 进制 一 .语言特性 python是一门动态解释性的强类型定义语言. 1.编译和解释语言: 简单讲,编译(compl ...

  8. 观察者模式(Observer)和发布(Publish/订阅模式(Subscribe)的区别

    观察者模式(Observer)和发布(Publish/订阅模式(Subscribe)的区别 在翻阅资料的时候,有人把观察者(Observer)模式等同于发布(Publish)/订阅(Subscribe ...

  9. GUI Design Studio的使用方法

    一.GUI Design Studio的介绍 GUI DesignStudio 是一个给应用软件设计图形用户界面的专业工具,它可在画基于web形态的原型时,可以用 Axure RP. Balsamiq ...

  10. Python 之map、filter、reduce

    MAP 1.Python中的map().filter().reduce() 这三个是应用于序列的内置函数,这个序列包括list.tuple.str. 格式: 1>map(func,swq1[,s ...