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

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. lnoi2019游记

    好诡异的省选...... day0: 莫名其妙的订了下午从sy到dl的火车,得五点多才能到,所以.......是不需要试机的吗...... 好吧... 看着停课的jflr们,感觉他们好强啊,像我这种酱 ...

  2. AI数据分析(一)

    安装Spyder+PyQt5 在python36目录下,使用cmd打开,切换到Scripts文件下 pip install spyder pip install PyQt5 python中的库 Num ...

  3. 论文阅读笔记四十:Deformable ConvNets v2: More Deformable, Better Results(CVPR2018)

    论文源址:https://arxiv.org/abs/1811.11168 摘要 可变形卷积的一个亮点是对于不同几何变化的物体具有适应性.但也存在一些问题,虽然相比传统的卷积网络,其神经网络的空间形状 ...

  4. (五)Knockout template模版渲染

    基础 template绑定通过模板将数据render到页面.模板绑定对于构建嵌套结构的页面非常方便.默认情况, Knockout用的是流行的jquery.tmpl模板引擎.使用它的话,需要在安装页面下 ...

  5. UOJ#110. 【APIO2015】Bali Sculptures 贪心 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ110.html 题解 我们发现n=2000 的子任务保证A=1! 分两种情况讨论: $n\leq 100$ ...

  6. 虚拟机Oracle VM VirtualBox linux系统如何访问windows共享文件夹

    1. 在本机系统设置一个共享文件夹,用于与Ubuntu交互的区域空间.     2.右击状态栏上共享文件夹图标或菜单栏“设备-共享文件夹”,打开共享文件夹设置,如图示   3.点击共享文件夹设置框,右 ...

  7. Selenium获取当前窗口句柄与切换回原窗口句柄

    Selenium通过window_handles获取当前窗口句柄,进行页面元素操作 切换回原窗口句柄,进行元素操作 代码如下:(python版) __author__ = 'liuke' import ...

  8. Spark环境搭建(二)-----------HDFS shell 常用操作

    配置好HDFS,也学习了点HDFS的简单操作,跟Linux命令相似 1)  配置Hadoop的环境变量,类似Java的配置 在 ~/.bash_profile 中加入 export HADOOP_HO ...

  9. spring集成rabbitmq

    https://www.cnblogs.com/nizuimeiabc1/p/9608763.html

  10. mysql Navicat 导入导出

    1.导出数据库:     打开Navicat ,在我们要导出的数据库上右击鼠标,然后弹出的快捷菜单上点击“转储SQL 文件”,(有些版本, 会有子菜单,在再次弹出的子菜单项中选择第一个“数据跟结构”) ...