第5讲:VUE3工程中实现页面加载中效果和页面切换动画效果。

Vue3页面加载与动画效果实现
部署运行你感兴趣的模型镜像

VUE3工程发布后的运行过程为先加载html面,再通过html页中的js加载单页面js来渲染页面并显示。

根据这个加载过程,实现页面加载中的原理是预先在html中显示加载中,再单页面数据加载完成在mounted时隐藏加载中,即实现想要的效果。

在public/index.html中添加加载中图层,对应的css自己根据需要设计即可。

    <div id="dvtop-app-loading">
      <div>
        <div class="dvtop-loader">
          <div class="dvtop-loading"></div>
        </div>
        <div class="text">页面加载中</div>
      </div>
    </div>

在src/App.vue隐藏加载中。

  mounted(){
    this.hideAppLoading();
  },
  methods: {
    hideAppLoading: function () {
      //删除加载中的图层
      const loadingLayer: any = document.getElementById("dvtop-app-loading");
      loadingLayer.style.opacity = "0.0";
      setTimeout(() => {
        document.body.removeChild( loadingLayer);
      }, 500); //此处时间要和#dvtop-app-loading的class中transition一致
    },
  }

对于页面切换动画效果借助animate.css动画包实现。
 

npm install animate.css -S

将src/App.vue中<router-view/>修改为如下代码。

    <router-view v-slot="{ Component }">
      <transition mode="out-in" :duration="300"
          enter-active-class="animate__animated animate__fadeIn"
          leave-active-class="animate__animated animate__fadeOut">
        <keep-alive>
          <component :is="Component"/>
        </keep-alive>
      </transition>
    </router-view>

具体动画可以根据需要使用animate.css,进入下面官方网站预览和使用。Animate.css | A cross-browser library of CSS animations.Animate.css is a library of ready-to-use, cross-browser animations for you to use in your projects. Great for emphasis, home pages, sliders, and attention-guiding hints.https://animate.style/运行如下代码,在浏览器中打开http://127.0.0.1:8080/即可访问。

cd dvtop-designer 
npm run serve

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DVTOP

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值