实现正在生成中的案例,并带有点点点动态效果

生成中后边带点点点动态效果,如图:

 

 

 

 

 

html
<template>
  <view>
    <text>{{ loadingText }}</text>
  </view>
</template>

<script>
export default {
  data() {
    return {
      loadingText: "正在生成中",
      timer: null,
      dots: ""
    };
  },
  mounted() {
    this.startLoadingAnimation();
  },
  methods: {
    startLoadingAnimation() {
      this.timer = setInterval(() => {
        if (this.dots.length === 3) {
          this.dots = "";
        } else {
          this.dots += ".";
        }
      }, 500);
    },
    stopLoadingAnimation() {
      clearInterval(this.timer);
    }
  },
  beforeDestroy() {
    this.stopLoadingAnimation();
  }
};
</script>

<style>
  /* 样式设置,根据需要自行修改 */
  view {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
  }
</style>

在上面的示例代码中,首先定义了loadingText用于显示生成中的文本信息,timer用于保存定时器的引用,dots用于保存点的动态效果。在mounted生命周期钩子中,调用startLoadingAnimation方法启动动态效果。在startLoadingAnimation方法中,使用setInterval函数每隔500毫秒更新一次dots,当点的个数达到3个时,将dots重置为空字符串,否则在dots后添加一个点。在beforeDestroy生命周期钩子中,调用stopLoadingAnimation方法停止定时器,以防止内存泄漏。

这样,页面就会显示"正在生成中"的文本,并伴随着点的动态效果,点的个数从1个到3个再循环。你可以根据需要修改样式和文本内容,以适配你的项目。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值