使用vue實(shí)現(xiàn)加載頁(yè)
更新時(shí)間:2022年07月05日 13:09:55 作者:歌聲緩緩
這篇文章主要為大家詳細(xì)介紹了使用vue實(shí)現(xiàn)加載頁(yè),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了用vue實(shí)現(xiàn)加載頁(yè)的具體代碼,供大家參考,具體內(nèi)容如下

<template>
? ? <div class="bac" style="height:1024px;display: flex;align-items: center;justify-content: center;">
? ? ? ? <div class="wrap-content">
? ? ? ? ? ? <img class="logo" src="../../assets/img/logo.png" :style="{'margin-left':percent}">
? ? ? ? ? ? <div class="bar">
? ? ? ? ? ? ? ? <div :style="{width:percent}" class="loadingBar">
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="percentFont">{{percent}}</div>
? ? ? ? ? ? <div class="fontTitle">報(bào)告生成中...</div>
? ? ? ? </div>
? ? </div>
</template>
<script>
? ? export default {
? ? ? ? name: "loading",
? ? ? ? data() {
? ? ? ? ? ? return{
? ? ? ? ? ? ? ? count: 0,
? ? ? ? ? ? ? ? percent:'0',
? ? ? ? ? ? ? ? imgs:[
? ? ? ? ? ? ? ? ? ? require("@/assets/img/bg.png"),
? ? ? ? ? ? ? ? ? ? require("@/assets/img/icon1.png"),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/icon2.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/icon3.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/icon4.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/icon5.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/icon6.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/loading-bg.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/logo.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/page3-title.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/pic1.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/pic2.png'),
? ? ? ? ? ? ? ? ? ? require('@/assets/img/pic3.png')
? ? ? ? ? ? ? ? ?)
? ? ? ? ? ? ? ? ]
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? mounted() {
? ? ? ? ? ? this.preload();
? ? ? ? },
? ? ? ? watch:{
? ? ? ? ? ? count: function (val) {
? ? ? ? ? ? ? ? if ( val === this.imgs.length) {
? ? ? ? ? ? ? ? ? ? // 圖片加載完成后跳轉(zhuǎn)頁(yè)面
? ? ? ? ? ? ? ? ? ? console.log(" 準(zhǔn)備就緒 >>>", val)
? ? ? ? ? ? ? ? ? ? this.$router.push({path: 'index'})
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? methods:{
? ? ? ? ? ? preload:function () {
? ? ? ? ? ? ? ? for (let img of this.imgs) {
? ? ? ? ? ? ? ? ? ? let image = new Image()
? ? ? ? ? ? ? ? ? ? image.src = img
? ? ? ? ? ? ? ? ? ? image.onload = () => {
? ? ? ? ? ? ? ? ? ? ? ? this.count++
? ? ? ? ? ? ? ? ? ? ? ? // 計(jì)算圖片加載的百分?jǐn)?shù),綁定到percent變量
? ? ? ? ? ? ? ? ? ? ? ? let percentNum = Math.floor(this.count / this.imgs.length * 100)
? ? ? ? ? ? ? ? ? ? ? ? if (percentNum == 100) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? percentNum = 99
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? this.percent = `${percentNum}%`
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>
<style scoped>
? ? .bac {
? ? ? ? width: 100%;
? ? ? ? background: url("../../assets/img/loading-bg.png") no-repeat top right;
? ? ? ? background-size: 100% 100%;
? ? ? ? overflow: hidden;
? ? ? ? position: relative;
? ? }
? ? .logo{
? ? ? ? width: 98px;
? ? ? ? height: 98px;
? ? }
? ? .percentFont {
? ? ? ? font-size: 32px;
? ? ? ? color: #046353;
? ? ? ? letter-spacing: 0.84px;
? ? ? ? text-align: center;
? ? ? ? margin-top: 32px;
? ? }
? ? .bar {
? ? ? ? margin-top: 50px;
? ? ? ? width: 300px;
? ? ? ? height: 8px;
? ? ? ? opacity: 0.8;
? ? ? ? background: #FFFFFF;
? ? ? ? border-radius: 4px;
? ? }
? ? .loadingBar {
? ? ? ? height: 8px;
? ? ? ? background-image: linear-gradient(-47deg, #046353 0%, #046353 100%);
? ? ? ? border-radius: 4px;
? ? }
? ? .fontTitle {
? ? ? ? margin-top: 12px;
? ? ? ? font-size: 32px;
? ? ? ? color: #046353;
? ? ? ? letter-spacing: 0.84px;
? ? ? ? text-align: center;
? ? ? ? font-weight: 400;
? ? }
</style>以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- vue實(shí)現(xiàn)加載頁(yè)面自動(dòng)觸發(fā)函數(shù)(及異步獲取數(shù)據(jù))
- 使用Vue實(shí)現(xiàn)調(diào)用接口加載頁(yè)面初始數(shù)據(jù)
- 淺談Vue.js 關(guān)于頁(yè)面加載完成后執(zhí)行一個(gè)方法的問題
- VUE頁(yè)面中加載外部HTML的示例代碼
- vue.js頁(yè)面加載執(zhí)行created,mounted的先后順序說(shuō)明
- 詳解vue頁(yè)面首次加載緩慢原因及解決方案
- 詳解Vue.js在頁(yè)面加載時(shí)執(zhí)行某個(gè)方法
- vue實(shí)現(xiàn)頁(yè)面加載動(dòng)畫效果
- Vue 路由切換時(shí)頁(yè)面內(nèi)容沒有重新加載的解決方法
- 解決vue項(xiàng)目中頁(yè)面調(diào)用數(shù)據(jù) 在數(shù)據(jù)加載完畢之前出現(xiàn)undefined問題
相關(guān)文章
vue配置文件自動(dòng)生成路由和菜單實(shí)例代碼
因?yàn)椴煌挠脩粲胁煌臋?quán)限,能訪問的頁(yè)面是不一樣的,所以我們?cè)趯懞笈_(tái)管理系統(tǒng)時(shí)就會(huì)遇過這樣的需求:根據(jù)后臺(tái)數(shù)據(jù)動(dòng)態(tài)添加路由和菜單,這篇文章主要給大家介紹了關(guān)于vue配置文件自動(dòng)生成路由和菜單的相關(guān)資料,需要的朋友可以參考下2021-08-08
Vue實(shí)現(xiàn)未登錄跳轉(zhuǎn)到登錄頁(yè)的示例代碼
本文主要介紹了Vue實(shí)現(xiàn)未登錄跳轉(zhuǎn)到登錄頁(yè)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
使用Vue如何寫一個(gè)雙向數(shù)據(jù)綁定(面試常見)
這篇文章主要介紹了使用Vue如何寫一個(gè)雙向數(shù)據(jù)綁定,在前端面試過程中經(jīng)常會(huì)問到,文中主要實(shí)現(xiàn)v-model,v-bind 和v-click三個(gè)命令,其他命令也可以自行補(bǔ)充。需要的朋友可以參考下2018-04-04
Vuex實(shí)現(xiàn)數(shù)據(jù)共享的方法
Vuex 是一個(gè)專為 Vue.js 應(yīng)用程序開發(fā)的狀態(tài)管理模式。這篇文章主要介紹了Vuex實(shí)現(xiàn)數(shù)據(jù)共享的方法,需要的朋友可以參考下2019-12-12
vue中input type=file上傳后@change事件無(wú)效的解決方案
這篇文章主要介紹了vue中input type=file上傳后@change事件無(wú)效的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05

