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() 实现的更多相关文章

  1. javascript图片加载完成前显示loading图片

    <html> <title>图片预加载</title> <body> <script> //判断浏览器 var Browser=new Ob ...

  2. vue+webpack项目打包后背景图片加载不出来问题解决

    在做VUE +的WebPack脚手架项目打包完成后,在IIS服务器上运行发现项目中的背景图片加载不出来检查项目代码发现是因为CSS文件中,背景图片引用的路径问题;后来通过修改配置文件,问题终于解决了, ...

  3. css背景图片加载失败,页面部分图标无法显示

    1.问题表现:首屏缺失部分图标.点击按钮切换为激活状态时,部分按钮的激活态图标无法显示. 2.问题原因:网络极差,断断续续,点击时添加class:active变为激活态, active.png这张图片 ...

  4. javscript 实现iframe加载内容页出现LOADING效果

    <div id="load" align="center"> <img src="http://sc.cnwebshow.com/u ...

  5. vue开发之图片加载不出来问题解决

    在使用vue开发项目的时候,经常会遇到的一个问题就是:图片加载不出来.下面是我总结的几种图片加载不出来的情况及解决办法. 一.项目打包完成后,打开整体空白 1.路径问题 原因 在vue+webpack ...

  6. vue项目未加载完成前显示loading...

    1.在Index.html里面加入loading的元素,让loading元素显示,让app元素隐藏 <!DOCTYPE html> <html> <head> &l ...

  7. vue中img图片加载中以及加载失败显示默认图片问题

    加载中默认图片:主要是onload事件监听,data中定义变量 imgSrc :require('./default.png'): <div class="per-pic" ...

  8. vue实现ajax滚动下拉加载,同时具有loading效果

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. vue中的图片加载与显示默认图片

    HTML: <div class="content-show-img"> <div class="show-img"> <img ...

随机推荐

  1. [Android GMS 认证] keystore/keymaster/Attestation的问题

    首先确定写入key,操作如下: 检查 /persist/data/sfs 目录下是否有key文件存在     adb shell ls -la /persist/data/sfs 做过key prov ...

  2. 第三方apk内置因签名导致SystemUI未启动启动问题案例分析

    这个问题是刷完机正常开机后,发现手机无状态栏,下拉通知栏,按音量键也无法出现VolumeDialog,开始看到这个现象感觉是systemUI未编译到版本中去?或者是在systemserver中syst ...

  3. Anaconda3 错误集合

    1. An error ocurred while starting the kernel 答:个人猜测有可能是配置文件出现问题,于是采用如下解决方法: 在终端中输入spyder --reset,重置 ...

  4. windows10 VM12 安装Mac OS X 10.11

    转载自:http://blog.csdn.net/j755ing/article/details/69400439 第一步: 下载 材料/工具: 下载 VMware Workstation 12 Pr ...

  5. MySQL 8.0 —— CATS事务调度算法的性能提升

    原文地址:https://mysqlserverteam.com/contention-aware-transaction-scheduling-arriving-in-innodb-to-boost ...

  6. 【PAT】B1027 打印沙漏(20 分)

    #include<cstdio> #include<stdlib.h> char C='*'; int qiushu(int hang){//输入行数,求出字符数 int su ...

  7. account

    Account Doc V3_ADD 1. 用户头像 用户头像今后会放在阿里云上,所以: dev: http(s)://pyserver.oss-cn-hangzhou.aliyuncs.com/DE ...

  8. Python中的 redis keyspace 通知

    介绍 Redis是内存中的数据结构存储,用于缓存.高速数据摄取.处理消息队列.分布式锁定等等. 与其他内存存储相比,使用Redis的优势在于它提供了持久性和数据结构,比如列表.集合.排序集合和散列. ...

  9. json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1

    问题描述:使用Python代码将txt城市列表文件转换为xls文件,源码如下, #!/usr/bin/env Python # coding=utf-8 import os import json i ...

  10. js中return,return true,return false三者的用法及区别

    return其实就是return undefined; 1.语法及返回方式 ①返回控制与函数结果 语法为:return 表达式; 语句结果函数的执行,返回调用函数,而且把表达式的值作为函数结果返回出去 ...