vue 首页背景图片加载完成前增加 loading 效果 -- 使用 new Image() 实现
1. 创建 loading 公用组件
<template>
<div class="load-container">
<div class="load"></div>
<div class="text">加载中...</div>
</div>
</template>
<script>
export default {
name: 'Loading',
}
</script>
<style scoped >
.load-container .load {
width: 60px;
height: 60px;
background-color: #1e8fc6;
margin: 50px auto;
animation: rotateplane 1.2s infinite ease-in-out;
}
.load-container .text {
text-align: center;
}
@keyframes rotateplane {
0% {
transform: perspective(120px) rotateX(0deg) rotateY(0deg);
} 50% {
transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
} 100% {
transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
}
}
</style>
loading效果如下:
需要在 login.vue 页面背景图完全加载完成之前显示上面的loading效果
2. login.vue 页面
<template>
<div>
<div class="loading-wrapper" v-show="showLoading">
<Loading></Loading>
</div>
<div class="login-wrapper" v-show="!showLoading">
<img :src="imgUrl" alt="" width="100%" height="100%">
<div class="login">
首页内容
</div>
</div>
</div>
</template>
<script>
import Loading from '@/components/loading/Loading.vue'
export default {
name: 'Login',
components: {
Loading
},
data() {
return {
showLoading: true, // 显示loading
imgUrl: require('../../assets/images/bg-img.jpg') // 背景图片地址
}
},
mounted () {
let bgImg = new Image()
bgImg.src = this.imgUrl // 获取背景图片的url
bgImg.onerror = () => {
console.log('img onerror')
}
bgImg.onload = () => { // 等背景图片加载成功后 去除loading
this.showLoading = false
}
},
methods: {
}
}
</script>
<style scoped>
.loading-wrapper {
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
background: #aedff8;
display: flex;
align-items: center;
justify-content: center;
}
.login-wrapper {
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
.login-wrapper img {
position: absolute;
z-index: 1;
}
.login {
max-width: 340px;
margin: 60px auto;
background: #fff;
padding: 20px 40px;
border-radius: 10px;
position: relative;
z-index: 9;
}
</style>
vue 首页背景图片加载完成前增加 loading 效果 -- 使用 new Image() 实现的更多相关文章
- javascript图片加载完成前显示loading图片
<html> <title>图片预加载</title> <body> <script> //判断浏览器 var Browser=new Ob ...
- vue+webpack项目打包后背景图片加载不出来问题解决
在做VUE +的WebPack脚手架项目打包完成后,在IIS服务器上运行发现项目中的背景图片加载不出来检查项目代码发现是因为CSS文件中,背景图片引用的路径问题;后来通过修改配置文件,问题终于解决了, ...
- css背景图片加载失败,页面部分图标无法显示
1.问题表现:首屏缺失部分图标.点击按钮切换为激活状态时,部分按钮的激活态图标无法显示. 2.问题原因:网络极差,断断续续,点击时添加class:active变为激活态, active.png这张图片 ...
- javscript 实现iframe加载内容页出现LOADING效果
<div id="load" align="center"> <img src="http://sc.cnwebshow.com/u ...
- vue开发之图片加载不出来问题解决
在使用vue开发项目的时候,经常会遇到的一个问题就是:图片加载不出来.下面是我总结的几种图片加载不出来的情况及解决办法. 一.项目打包完成后,打开整体空白 1.路径问题 原因 在vue+webpack ...
- vue项目未加载完成前显示loading...
1.在Index.html里面加入loading的元素,让loading元素显示,让app元素隐藏 <!DOCTYPE html> <html> <head> &l ...
- vue中img图片加载中以及加载失败显示默认图片问题
加载中默认图片:主要是onload事件监听,data中定义变量 imgSrc :require('./default.png'): <div class="per-pic" ...
- vue实现ajax滚动下拉加载,同时具有loading效果
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- vue中的图片加载与显示默认图片
HTML: <div class="content-show-img"> <div class="show-img"> <img ...
随机推荐
- C# winform三种定时方法
1. 直接用winform 的 timers 拖控件进去 代码 public partial class Form1 : Form { public Form1() ...
- git将本地项目推送到远程仓库
一.三个基本配置: Git全局设置 git config --global user.name "账户名称" git config --global user.email &quo ...
- linux上文件内容去重的问题uniq/awk
1.uniq:只会对相邻的行进行判断是否重复,不能全文本进行搜索是否重复,所以往往跟sort结合使用. 例子1: [root@aaa01 ~]# cat a.txt 12 34 56 12 [root ...
- 实战:阿里巴巴 DevOps 转型后的运维平台建设
导读:阿里巴巴DevOps转型之后,运维平台是如何建设的?阿里巴巴高级技术专家陈喻结合运维自身的理解,业务场景的分析和业界方法论的一些思考,得出来一些最佳实践分享给大家. 前言 “我是这个应用 ...
- HashMap探究
HashMap 前置 //初始化容量 static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; //容器最大容量 static final i ...
- 【PAT】B1032 挖掘机技术哪家强(20 分)
#include<cstdio> const int maxx= 100010; int school[maxx]={0}; int main() { int n,schid,schsco ...
- 2.2Python数据处理篇之---math模块的数学函数
目录 目录 前言 (一)一览表 1.基本函数 2.对数函数 3.三角函数 4.角度的切换 5.双曲函数 6.math定义的常数 (二)实例 目录 前言 math模块是基础的python数学函数模块,是 ...
- Linux 小知识翻译 - 「RAID」
最近术语「RAID」变得比较有名.「RAID」是指将多个HDD组合起来使用,从而提高存储可靠性的一种技术. 那么,关于 RAID 中的 「RAID 0」「RAID 1」「RAID 5」等各种「RAID ...
- NavigationController相关颜色设置
一.当push进去一个界面后,返回按钮颜色改变: self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
- deepin安装Oracle jdk8,以及添加add-apt-repository命令支持
@font-face{ font-family:"Times New Roman"; } @font-face{ font-family:"宋体"; } p.M ...