uniapp回到上一页

回到上一页代码uniapp中代码

javascript 复制代码
<template>
	<view class="my_footer">
		<view class="m_goBack" @click.stop="handlergoBack()"></view>
		<view class="m_index"  @click.stop="handlergoIndex()"></view>
	</view>
</template>

<script>
	export default {
		methods: {
			//回到上一个页面
			handlergoBack() {
				//如果没有上一个页面 就回到首页
				const pages = getCurrentPages();
				if (pages.length === 2) {
					uni.navigateBack({
						delta: 1
					});
				} else if (pages.length === 1) {
					uni.switchTab({
						url: '/pages/index/index',
					})
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
			//回到首页
			handlergoIndex(){
				uni.switchTab({
					url:'/pages/index/index'
				})
			}

		}
	}
</script>

<style lang="scss">
	.my_footer {
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 96rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 88;
		.m_index {
			flex: 1;
			height: 96rpx;
			background: url('@/static/home.png') center no-repeat;
			background-size: 32rpx 30rpx;
			
		}
		.m_goBack {
			flex: 1;
			width: 80rpx;
			height: 96rpx;
			background: url('@/static/back.png') center no-repeat;
			background-size: 20rpx 32rpx;
		}
	}
</style>
相关推荐
2601_958492552 小时前
Optimizing Engagement with Freehead Skate - HTML5 Game - Construct 3
前端·html·html5
茉莉玫瑰花茶3 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
zhangxingchao4 小时前
AI应用开发六:企业知识库
前端·人工智能·后端
山峰哥4 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘
前端·数据库·sql·性能优化
红尘散仙4 小时前
一个 `#[uniffi::export]`,把 Rust 接进 React Native
前端·后端·rust
moshuying4 小时前
AI Coding 最大的 token 黑洞,可能根本不是 prompt
前端
红尘散仙4 小时前
一行 `#[specta::specta]`,让 Tauri IPC 有类型
前端·后端·rust
lichenyang4535 小时前
HarmonyOS HMRouter 接入记录:从普通 Tab Demo 到路由跳转
前端
木斯佳5 小时前
前端八股文面经大全:腾讯WXG暑期前端一面(2026-05-15)·面经深度解析
前端·面试·笔试