loading這里寫了3種效果
1. 全局loading
2. aside loading
3. dialog loading
演示

代碼
~~~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>loading</title>
<script type="text/javascript" src="vue.min.js"></script>
<style>
.zh-loading{width:100px;height:100px;position:relative;margin:0 auto;}
.zh-loading span{display:inline-block;width:16px;height:16px;border-radius:50%;background:#90ee90;position:absolute;-webkit-animation:load 1.04s ease infinite}
@-webkit-keyframes load{0%{-webkit-transform:scale(1.2);opacity:1}
100%{-webkit-transform:scale(.3);opacity:.5}
}
.zh-loading span:nth-child(1){left:0;top:50%;margin-top:-10px;-webkit-animation-delay:.13s}
.zh-loading span:nth-child(2){left:14px;top:14px;-webkit-animation-delay:.26s}
.zh-loading span:nth-child(3){left:50%;top:0;margin-left:-10px;-webkit-animation-delay:.39s}
.zh-loading span:nth-child(4){top:14px;right:14px;-webkit-animation-delay:.52s}
.zh-loading span:nth-child(5){right:0;top:50%;margin-top:-10px;-webkit-animation-delay:.65s}
.zh-loading span:nth-child(6){right:14px;bottom:14px;-webkit-animation-delay:.78s}
.zh-loading span:nth-child(7){bottom:0;left:50%;margin-left:-10px;-webkit-animation-delay:.91s}
.zh-loading span:nth-child(8){bottom:14px;left:14px;-webkit-animation-delay:1.04s}
.zh-loading-box{position: absolute;z-index: 999;left: 0;top: 0;height: 100%;width: 100%;background: rgba(0,0,0,0.1);}
.zh-loading-box .zh-loading-inner{position: absolute;z-index: 2;left: 50%;top: 50%;-webkit-transform: translate(-50%, -50%);-ms-transform: translate(-50%, -50%);transform: translate(-50%, -50%);}
.zh-loading-box .zh-loading-inner p{color: #666;text-align: center;}
.fade-enter-active, .fade-leave-active{-webkit-transition: opacity .5s;transition: opacity .5s;}
.fade-enter, .fade-leave-to{opacity: 0;}
</style>
</head>
<body>
<div id="app">
<!-- 全局loading -->
<loading ref="global" v-show="loading.global" v-bind:style="[style.global]"></loading>
<button v-bind:style="[style.btn]" type="button" v-on:click="globalLoading">顯示全局loading</button>
<!-- aside loading -->
<div v-bind:style="[style.aside]">
<loading v-show="loading.aside"></loading>
</div>
<button v-bind:style="[style.btn]" type="button" v-on:click="asideLoading">顯示aside loading</button>
<!-- dialog loading -->
<transition name="fade">
<div v-show="loading.dialog" v-bind:style="[style.dialog]">
<loading></loading>
</div>
</transition>
<button v-bind:style="[style.btn]" type="button" v-on:click="dialogLoading">顯示dialog loading</button>
</div>
<!-- loading template -->
<script type="text/x-template" id="loading">
<div class="zh-loading-box">
<div class="zh-loading-inner">
<div class="zh-loading">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<p>{{ text }}</p>
</div>
</div>
</script>
<script>
// 變量
var timeout = null;
// 組件
Vue.component('loading', {
template: '#loading',
data: function() {
return {
text: '正在加載...'
}
}
});
// 實例
var app = new Vue({
el: '#app',
data: {
loading: {
global: false,
aside: false,
dialog: false
},
style: {
global: {
position: 'fixed'
},
btn: {
position: 'relative',
zIndex: 1000
},
aside: {
position: 'relative',
float: 'right',
width: '300px',
height: '600px',
backgroundColor: '#eee',
boxShadow: '0 0 5px rgba(0,0,0,0.3)'
},
dialog: {
position: 'fixed',
zIndex: 999,
left: '50%',
top: '50%',
width: '500px',
height: '500px',
backgroundColor: '#ccc',
border: '1px solid #aaa',
boxShadow: '0 0 10px rgba(0,0,0,0.3)',
transform: 'translate(-50%,-50%)'
}
}
},
methods: {
globalLoading: function(e) {
if(/^顯示/.test(e.target.innerText)) {
e.target.innerText = '隱藏全局loading';
this.style.global.position = 'fixed';
} else {
e.target.innerText = '顯示全局loading';
this.style.global.position = 'absolute';
this.$refs.global.text = '正在加載...';
}
this.loading.global = !this.loading.global;
if(timeout) {
clearTimeout(timeout);
timeout = null;
}
timeout = setTimeout(function() {
this.$refs.global.text = '==== 加載完成 ====';
}.bind(this), 1000);
},
asideLoading: function(e) {
if(/^顯示/.test(e.target.innerText)) {
e.target.innerText = '隱藏aside loading';
} else {
e.target.innerText = '顯示aside loading';
}
this.loading.aside = !this.loading.aside;
},
dialogLoading: function(e) {
if(/^顯示/.test(e.target.innerText)) {
e.target.innerText = '隱藏dialog loading';
} else {
e.target.innerText = '顯示dialog loading';
}
this.loading.dialog = !this.loading.dialog;
}
}
});
</script>
</body>
</html>
~~~
dialog的過渡效果使用了transition內置組件,但個人覺得還是自己寫個class來的方便,可能是不習慣吧。。
這里感覺使用組件的好處是,頁面標簽更少了,結構也不較清晰,組件復用也很方便。。

- 事件
- mouse縮放與拖動
- drag拖動
- 事件兼容
- animation/transition
- canvas
- 改變圖片顏色
- html轉圖片
- 視頻操作
- 圖片縮放、水印、放大鏡
- 虛線
- 圓環進度條
- 形狀事件
- 圓角矩形
- 繪制注意
- arcTo與貝塞爾
- 橢圓及橢圓進度
- 五角星進度
- 常用圖形
- 計算顯示文本寬度
- 算法
- 幾何算法
- 地圖應用相關
- 運行符
- web安全
- 新窗口打開
- xss
- 分享交流
- php環境搭建及xhr交互
- node環境搭建及xhr交互
- node之socketio
- svg之入門介紹
- svg動畫
- vue之搜索聯想
- vue之登錄和echarts
- vue之組件交互與slot
- vue之loading
- vue之上傳進度
- webpack及cli
- 開發技巧
- 常用
- 移動端
- 錯誤處理
- 預加載
- 代理判斷
- 數組擴展
- 對象擴展
- 字符串擴展
- 語音播報
- 收集
- 文章/日記
- 框架/庫/插件
- 工具
- 學習網站
- 專業術語
- 正則
- 常用驗證
- 方法基礎
- es6擴展
- 深入實踐
- 快捷使用
- html
- css
- http協議
- http
- https
- socket
- 地圖/圖表
- mapbox
- echarts
- arcgis
- MapView及事件
- 添加WMS/WMTS層
- 增刪點線面
- 入門使用
- popup彈層
- 大數據處理
- 批量點
- 批量線
- 在線繪制
- GraphicLayer顯示/隱藏
- 動態改變位置
- 去除版權信息
- 添加控件
- Symbol
- 自定義path標記
- 圖片標記
- 文本標記
- 旋轉
- UI
- 自定義
- 3D地圖
- 創建實例
- basemap
- 底圖切換
- 自定義底圖
- 中心和范圍
- pupup彈層更新
- 坐標轉換
- 方向線
- leaflet
- amap
- 框架/類庫/腳手架
- vue
- 常見問題
- 組件框架
- vue-router
- 命名視圖
- url參數映射到prop
- sublime支持
- 隨手記
- 常用功能
- threejs
- 常用效果
- 其他特效
- requirejs
- 簡單使用
- jquery
- 方法擴展
- 使用筆記
- 組件擴展
- react
- 黨見問題
- 學習筆記
- 學習筆記-進階
- react-redux
- react-router
- redux
- 其他模塊說明
- 組件框架
- sublime支持
- gulp
- 安裝使用
- js壓縮
- css壓縮
- 組合使用
- copy文件
- 項目使用
- protobuf
- 入門
- layui
- 登錄驗證
- laydate
- 安裝工具
- yarn
- reactNative
- 入門介紹
- vueNative
- 入門介紹
- 版本控制
- git常用
- git擴展
- git問題
- git其他
- git擴展2
- 編輯器
- vscode
- atom
- webstorm
- 插件
- clipboard
- 奇淫巧技
- js
- 個性打印
- css
- 濾鏡效果
- 文本省略
- 當前色
- 新特性
- 花樣邊框效果
- 波紋效果
- 個性placeholder
- 偽元素內容
- 容器居中
- 知識點
- js
- 遞歸
- 沙箱
- 內存泄漏
- es6語法
- 變量介紹
- FileRead
- ajax
- web存儲
- css
- rem布局