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

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. Groovy闭包

    定义 闭包(Closure)是一种数据类型,它代表一段可执行的代码.它可以作为方法的参数,或者返回值,也可以独立运行,定义如下: def xxx = {parameters -> code}   ...

  2. element ui table单选框点击全选问题

    <template slot-scope="scope"> <el-radio-group v-model="scope.row.HandleState ...

  3. mysql查看索引与锁

    http://www.cnblogs.com/cocos/archive/2011/05/06/2039428.html Mysql乐观锁与悲观锁 http://www.cnblogs.com/esi ...

  4. Python学习(三十六)—— Cookie、Session和自定义分页

    一.Django中操作Cookie 获取Cookie request.COOKIES['key'] request.get_signed_cookie(key, default=RAISE_ERROR ...

  5. Spark安装部署| 运行模式

    Spark 一种基于内存的快速.通用.可扩展的大数据分析引擎: 内置模块: Spark Core(封装了rdd.任务调度.内存管理.错误恢复.与存储系统交互): Spark SQL(处理结构化数据). ...

  6. UVA 10474 - Where is the Marble?--vector

    https://vjudge.net/problem/UVA-10474 https://blog.csdn.net/xiyaozhe/article/details/81081344 简单用法 so ...

  7. django中widget小部件

    1. 处理 input 的部件 TextInput    NumberInput EmailInput URLInput PasswordInput HiddenInput DateInput Dat ...

  8. .net程序员面试小结(内附一些面试题和答案)

    今天下午去面试,面试官和HR小姐姐都很好,没有做面试题,用聊天的方式来交流技术,整个过程很轻松,从中也学到了很多知识. 下面就来总结一下面试过程. 一.深刻了解自己的简历 无论是HR还是技术面试人,首 ...

  9. 使用163.com邮箱发送邮件

    不要直接使用登录的密码,而是用配置中的授权码做为密码

  10. JQuery 目录树jsTree插件用法

    PHP循环构造目录树结构 <ul> <php> function digui($fid,$level){ $class=M("wangpan_class") ...