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 ...
随机推荐
- Asp.Net Core 使用Quartz基于界面画接口管理做定时任务
今天抽出一点点时间来造一个小轮子,是关于定时任务这块的. 这篇文章主要从一下几点介绍: 创建数据库管理表 创建web项目 引入quarzt nuget 包 写具体配置操作,实现定时任务处理 第一步:创 ...
- 第七章 鼠标(CHECKER4)
/*--------------------------------------------- CHECKER4.C -- Mouse Hit-Test Demo Program No.4 (c) C ...
- sklearn datasets模块学习
sklearn.datasets模块主要提供了一些导入.在线下载及本地生成数据集的方法,可以通过dir或help命令查看,我们会发现主要有三种形式:load_<dataset_name>. ...
- 自定义mysql类用于快速执行数据库查询以及将查询结果转为json文件
由于每次连接数据库进行查询比较麻烦,偶尔还需要将查询结果转为json格式的文件, 因此暂时定义一个mysql的类,将这些常用的方法进行封装,便于直接调用(代码如下,个人用,没写什么注释). 注:导入了 ...
- ABAP 在被访问的程序中获取访问程序的全局变量
前些日子接到过一个看起来比较普通的需求: 存在一个系统标准函数组FG01,内含函数模块FM00,FM01……等等.在系统程序中,FM00会调用FM01,通过FM01获取获取某些数据. 需求要求,复制一 ...
- C# Repeater、webdiyer:AspNetPager分页 AspNetPager分页样式
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/vaecnfeilong/article/details/32712611 AspNetPager分页 ...
- 2018-2019-2 网络对抗技术 20165318 Exp5 MSF基础应用
2018-2019-2 网络对抗技术 20165318 Exp5 MSF基础应用 原理与实践说明 实践原理 实践内容概述 基础问题回答 攻击实例 主动攻击的实践 ms08_067_netapi:自动化 ...
- oracle 迁移
一.创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建. create directory exp_shengchan as '/home/oracle/exp_shen ...
- matlab padarray函数
1 padarray功能:填充图像或填充数组.用法:B = padarray(A,padsize,padval,direction) A为输入图像,B为填充后的图像, padsize给出了给 ...
- python链家网高并发异步爬虫asyncio+aiohttp+aiomysql异步存入数据
python链家网二手房异步IO爬虫,使用asyncio.aiohttp和aiomysql 很多小伙伴初学python时都会学习到爬虫,刚入门时会使用requests.urllib这些同步的库进行单线 ...