当前位置: 首页 > news >正文

微信小程序封装loading 修改

1.  custom-loading.vue

<template><view v-if="visible" class="custom-loading-mask" @touchmove.stop.prevent><view class="custom-loading-container"><!-- 动态点点 --><text class="loading-text">{{ text }}{{ dots }}</text></view></view>
</template><script>
export default {props: {visible: Boolean,text: {type: String,default: '加载中'}},data() {return {dots: '',timer: null}},mounted() {this.startAnimation()},beforeDestroy() {clearInterval(this.timer)},methods: {startAnimation() {this.timer = setInterval(() => {this.dots = this.dots.length >= 3 ? '' : this.dots + '.'}, 500)}}
}
</script><style scoped>
/* 保持相同的容器样式 */
.custom-loading-mask {position: fixed;top: 0;left: 0;right: 0;bottom: 0;background-color: rgba(0, 0, 0, 0.5);z-index: 9999;display: flex;justify-content: center;align-items: center;
}.custom-loading-container {background-color: #2e2e2e;color: #fff;border-radius: 8px;padding: 24px 32px;min-width: 120px;text-align: center;
}.loading-text {font-size: 16px;color: #fff;
}
</style>

2.loading.js  

import Vue from 'vue'
import CustomLoading from './custom-loading.vue'const LoadingConstructor = Vue.extend(CustomLoading)
let loadingInstance = nullexport const showLoading = (options = {}) => {if (loadingInstance) returnloadingInstance = new LoadingConstructor({el: document.createElement('div'),propsData: {visible: true,text: options.text || '加载中...',color: options.color || '#1e7061'}})document.body.appendChild(loadingInstance.$el)// 超时自动关闭if (options.timeout) {setTimeout(() => {hideLoading()}, options.timeout)}
}export const hideLoading = () => {if (loadingInstance) {loadingInstance.visible = falsesetTimeout(() => {if (loadingInstance.$el && loadingInstance.$el.parentNode) {loadingInstance.$el.parentNode.removeChild(loadingInstance.$el)}loadingInstance.$destroy()loadingInstance = null}, 300)}
}// 全局混入
Vue.mixin({methods: {$showLoading(options) {showLoading(options)},$hideLoading() {hideLoading()}}
})

3.引用

<CustomLoading :visible="isLoading" text="正在上传图片..." />

    import CustomLoading from '@/workpages/components/custom-loading.vue'

http://www.lryc.cn/news/575805.html

相关文章:

  • 常见网络安全威胁和防御措施
  • 智能实验室革命:Deepoc大模型驱动全自动化科研新生态
  • HTML简介,初步了解HTML
  • SQl中多使用EXISTS导致多查出了一条不符合条件的数据
  • 教程 | 一键批量下载 Dify「Markdown 转 Docx」生成的 Word 文件(附源码)
  • 【Linux】基础开发工具(2)
  • 操作系统面试知识点(1):操作系统基础
  • CyberGlove触觉反馈手套遥操作机器人灵巧手解决方案
  • Kotlin环境搭建与基础语法入门
  • 大厂测开实习和小厂开发实习怎么选
  • 华为云鸿蒙应用入门级开发者认证 实验(HCCDA-HarmonyOS Cloud Apps)
  • linux网络编程socket套接字
  • mysql无法启动的数据库迁移
  • WebSocket 与 HTTP 的区别及 Spring Boot 实战应用
  • [AI]从0到1通过神经网络训练模型
  • 128K 长文本处理实战:腾讯混元 + 云函数 SCF 构建 PDF 摘要生成器
  • C++智能指针概念及std::unique_ptr使用介绍
  • 【办公类-105-01】20250626 托小班报名表-条件格式-判断双胞胎EXCLE
  • CNN不是一个模型?
  • 跨越十年的C++演进:C++14新特性全解析
  • C++(模板与容器)
  • Java--程序控制结构(下)
  • springcloud 尚硅谷 看到9开头
  • NebulaGraph 图数据库介绍
  • 一分钟了解Transformer
  • 缓存与加速技术实践-MongoDB数据库应用
  • AI+时代已至|AI人才到底该如何培育?
  • Python打卡:Day37
  • 快速傅里叶变换(FFT)是什么?
  • 4.2_1朴素模式匹配算法