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

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.dtcms.com/a/279752.html

相关文章:

  • 基于HarmonyOS的智能灯光控制系统设计:从定时触发到动作联动全流程实战
  • C++ 中常见的字符串定义方式及其用法
  • 1111自己
  • 基础分类模型及回归简介(一)
  • 体验RAG GitHub/wow-rag
  • 前端同学,你能不能别再往后端传一个巨大的JSON了?
  • 引用(C++)
  • python的微竞网咖管理系统
  • ⽂本预处理(一)
  • volatile 关键字
  • Codeforces Round 787 (Div. 3)(A,B,C,D,E,F,G)
  • DO,VO,DTO.....
  • (二十四)-java+ selenium自动化测试-三大延时等待
  • UI前端与数字孪生融合案例:智慧城市的智慧停车引导系统
  • 苍穹外卖Day4
  • JavaScript进阶篇——第二章 高级特性核心
  • vue笔记4 vue3核心语法和pinia基础使用
  • 【leetcode】326. 3的幂
  • VSCode中使用容器及容器编排docker-compose
  • L1与L2正则化详解:原理、API使用与实践指南
  • FastAPI + gRPC 全栈实践:Windows 开发到 Ubuntu 部署全指南
  • JVM监控及诊断工具-命令行篇
  • ubuntu 22.04 anaconda comfyui安装
  • 8.数据库索引
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘collections’问题
  • WIFI MTU含义 ,协商修改的过程案例分析
  • ansys2021R Fluent 的UDF配置问题
  • 开疆智能EtherCAT转CANopen网关连接磁导航传感器配置案例
  • 《美术教育研究》是什么级别的期刊?是正规期刊吗?能评职称吗?
  • Python项目中Protocol Buffers的应用示例