国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Vue 全局loading組件實例詳解

2019-11-19 13:45:37
字體:
來源:轉載
供稿:網友

上圖不上種,菊花萬人捅:

loading.js:

import './loading.css' let Loading = {}// 避免重復install,設立flagLoading.installed = falseLoading.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組件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沙湾县| 农安县| 文水县| 忻城县| 格尔木市| 墨竹工卡县| 栾川县| 施甸县| 临江市| 浠水县| 岑巩县| 昆山市| 惠东县| 安福县| 庆安县| 比如县| 汤阴县| 且末县| 普安县| 彭泽县| 两当县| 兖州市| 潞城市| 洞口县| 乌兰县| 田阳县| 隆回县| 颍上县| 宁都县| 高平市| 同江市| 温州市| 乌兰浩特市| 台湾省| 安陆市| 大宁县| 五家渠市| 凌海市| 兖州市| 张家港市| 萨嘎县|