≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > vue.js

Vue 全局loading组件实例分析

人气:420 时间:2019-04-11

这篇文章主要为大家详细介绍了Vue 全局loading组件实例分析,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!

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

【图片暂缺】

 

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);
}

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

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

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

 

总结

 

以上所述是小编给大家介绍的Vue 全局loading组件,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对四海网网站的支持!

本文来自:http://www.q1010.com/184/5468-0.html

注:关于Vue 全局loading组件实例分析的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:vue.js

您可能感兴趣的文章

  • 讲解vue-router之什么是嵌套路由
  • 深入理解Vue Computed计算属性原理
  • 分析vue-router 命名路由和命名视图
  • 讲解vue-router之命名路由和命名视图
  • 讲解vue-router之什么是编程式路由
  • vue-cli构建项目下使用微信分享功能
  • 最后说说Vue2 SSR 的 Cookies 问题
  • 讲解vue-router之什么是动态路由
  • vue-cli项目中使用公用的提示弹层tips或加载loading组件实例分析
  • Vue 组件传值几种常用方法【总结】
上一篇:vue源码学习之Object.defineProperty对象属性监听
下一篇:深入理解Vue Computed计算属性原理
热门文章
  • Vue 报错TypeError: this.$set is not a function 的解决方法
  • vue实现动态添加数据滚动条自动滚动到底部的示例代码
  • vue项目设置scrollTop不起作用(总结)
  • vue项目中使用vue-i18n报错的解决方法
  • iview实现select tree树形下拉框的示例代码
  • 分析关于element级联选择器数据回显问题
  • vue项目打包后打开页面空白解决办法
  • 解决element ui select下拉框不回显数据问题的解决
  • element-ui table span-method(行合并)的实现代码
  • element-ui 设置菜单栏展开的方法
  • 最新文章
    • 理解vue ssr原理并自己搭建简单的ssr框架
    • vue favicon设置以及动态修改favicon的方法
    • vue-router启用history模式下的开发及非根目录部署方法
    • 从零开始在NPM上发布一个Vue组件的方法步骤
    • Element input树型下拉框的实现代码
    • Vue 报错TypeError: this.$set is not a function 的解决方法
    • Vue.js组件高级特性实例分析
    • 浅谈VueJS SSR 后端绘制内存泄漏的相关解决经验
    • 分析Vue.js自定义tipOnce指令用法实例
    • 浅谈vuex actions和mutation的异曲同工

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。