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 ...
随机推荐
- (网页)JS中的小技巧,但十分的实用!
转自CSDN: 1.document.write(”"); 输出语句2.JS中的注释为//3.传统的HTML文档顺序是:document->html->(head,body)4. ...
- node中__dirname、__filename、process.cwd()、process.chdir()表示的路径
直接上结论:__dirname 表示当前文件所在的目录的绝对路径__filename 表示当前文件的绝对路径module.filename ==== __filename 等价process.cwd( ...
- Echarts地图展示及属性分析
Echarts,一个效果非常棒的可视化库,可以生产各种图表,动态展示,附上官方网址:http://www.echartsjs.com/index.html 之前带本科实习时有同学用过,狗哥的博客也用这 ...
- [20180806]tune2fs调整保留块百分比.txt
[20180806]tune2fs调整保留块百分比.txt --//生产系统一台dg磁盘空间满了.我前一阵子已经将*convert参数修改,增加磁盘,但是这个分区里面的数据文件还可以增长,这样依旧存- ...
- momentjs 学习
momentjs 是一个JavaScript日期处理类库,官网地址:http://momentjs.com/ 字符串 + 格式 moment(String, String); moment(Strin ...
- 禁用selinux
查看selinux状态: [root@VM000000518 upload]# getenforce Enforcing 禁用: [root@VM000000518 upload]# setenfor ...
- php二维数组去重
php二维数组去重 前言:php一维数组去重很简单,直接array_unique($arr)即可,但是二维数组去重就得自己去写了 二维数组去重方法: /* * 二维数组去重 * 注意:二维数组中的元素 ...
- win7系统保护配置现错误“文件名、目录名或卷标语法不正确。(0x8007007B)
windows7下系统保护功能很是鸡肋,有事会出现一下两个问题: 1.出现错误“文件名.目录名或卷标语法不正确.(0x8007007B) 2.保护设置列表中出现“Windows7_os(c:)(找不到 ...
- Win10更换电脑,又不想重装系统的解决方法
问题描述: 在公司因为两年前用的i3的电脑很卡,然后想换i5的电脑,但是又不想重装系统,因为安装的东西太多了,重装很麻烦 Windows to go介绍: Windows To Go是Windows ...
- Django【进阶篇】
目录 一.Model 二.admin 三.Form组件 四.Cookie 五.Session 六.分页 七.序列化 一.Model 数据库的配置 1.django默认支持sqlite,mysql, o ...