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

uni-app开发的页面跳转全局加载中

uni-app开发的页面跳转全局加载中

    • 首先需要下载插件
    • 创建加载中页面组件
    • app.vue页面中监听跳转

首先需要下载插件

https://ext.dcloud.net.cn/plugin?id=20613

创建加载中页面组件

<!-- 全局自定义加载中 -->
<template><view v-if="visible" class="global-loading"><!-- 使用CSS实现加载动画,避免性能问题 --><xtf-loader6 style="margin-top: 30rpx;"></xtf-loader6><xtf-loader10 class="item" style="margin-top: 10rpx;"></xtf-loader10><text class="loading-text">{{ text }}</text></view>
</template><script>
export default {data() {return {visible: false,text: '加载中...'}},methods: {show(text) {this.text = text || '加载中...'this.visible = true},hide() {this.visible = false}}
}
</script><style scoped>
.global-loading {position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: rgba(255, 255, 255, 1);display: flex;flex-direction: column;justify-content: center;align-items: center;z-index: 9999;
}.loading-spinner {display: flex;margin-bottom: 16px;
}.spinner-dot {width: 12px;height: 12px;margin: 0 6px;background-color: #007aff;border-radius: 100%;animation: spinner-bounce 1.4s infinite ease-in-out both;
}.spinner-dot:nth-child(1) {animation-delay: -0.32s;
}.spinner-dot:nth-child(2) {animation-delay: -0.16s;
}@keyframes spinner-bounce {0%, 80%, 100% { transform: scale(0);opacity: 0.5;} 40% { transform: scale(1);opacity: 1;}
}.loading-text {font-size: 14px;margin-top: 15px;color: #666;
}
</style>


这个就是那个插件里面的小组件,可以用在加载中进行显示,插件下载安装好后,就这样直接使用代码去调用,不用再多做别的配置。

app.vue页面中监听跳转

<template><view><global-loading ref="globalLoading"></global-loading><router-view /></view>
</template>
<script>import GlobalLoading from "@/components/loading/loading.vue"export default {onLaunch: function() {console.log('App Launch')// 初始化路由拦截this.setupRouterInterceptor()},onShow: function() {console.log('App Show')},onHide: function() {console.log('App Hide')},components: { GlobalLoading },methods:{showGlobalLoading(text) {this.$refs.globalLoading.show(text)},hideGlobalLoading() {this.$refs.globalLoading.hide()},setupRouterInterceptor() {const interceptorMethods = ['navigateTo','redirectTo','reLaunch','switchTab']interceptorMethods.forEach(method => {uni.addInterceptor(method, {invoke: (args) => {this.showGlobalLoading('加载中...')return args},success: () => {// 确保页面切换完成后再隐藏setTimeout(() => {this.hideGlobalLoading()}, 1500)},fail: (err) => {this.hideGlobalLoading()console.error('导航失败:', err)},complete: () => {// 兜底确保loading关闭setTimeout(() => {this.hideGlobalLoading()}, 2000)}})})},}}
</script><style>/*每个页面公共css */
</style>

这样就可以实现页面跳转的时候进行加载中显示了!!!

http://www.xdnf.cn/news/15323.html

相关文章:

  • QT——信号与槽
  • git 访问 github
  • 《恋与深空》中黑白羽毛是谁的代表物?
  • python+Request提取cookie
  • ubuntu22.04下配置qt5.15.17开发环境
  • Elasticsearch9.x核心架构概述
  • 机器学习、深度学习、神经网络之间的关系
  • 多租户云环境下的隔离性保障:虚拟化、容器、安全组如何协同防护?
  • 高德开放平台携手阿里云,面向开发者推出地图服务产品MCP Server
  • Redis技术笔记-主从复制、哨兵与持久化实战指南
  • 工业场合需要千变万化的模拟信号,如何获取?
  • Servlet基础
  • priority_queue的使用和模拟实现以及仿函数
  • FatJar打包和FatJar启动配置文件修改。
  • 对偶原理与蕴含定理
  • [论文阅读] 人工智能 + 软件工程 | 用大语言模型+排名机制,让代码评论自动更新更靠谱
  • Ubuntu22.04 python环境管理
  • 深度解析:htmlspecialchars 与 nl2br 结合使用的前后端协作之道,大学毕业论文——仙盟创梦IDE
  • nginx:SSL_CTX_use_PrivateKey failed
  • 【HTTP版本演变】
  • Python 数据建模与分析项目实战预备 Day5 - 模型训练与评估
  • 九、官方人格提示词汇总(中-1)
  • (LeetCode 每日一题) 1290. 二进制链表转整数 (链表+二进制)
  • Kafka 时间轮深度解析:如何O(1)处理定时任务
  • 前端docx库实现将html页面导出word
  • 【第一章编辑器开发基础第二节编辑器布局_3间距控制(4/4)】
  • Java 大视界 -- 基于 Java 的大数据可视化在城市地下管网管理与风险预警中的应用
  • 显示器核心三要素详解:刷新率、分辨率、色深
  • SpringBoot-26-企业云端开发实践之Vue框架状态管理VueX和数据模拟MockJS
  • 从零构建搜索引擎 build demo search engine from scratch