小程序中的页面跳转

小程序中的页面跳转

在之前网页的学习中,我们往往采用超链接,或者定义方法、函数等方式来实现页面的跳转,但是微信小程序中没有超链接,那我们该如何实现呢?微信小程序的页面跳转包括两个,一个是tabBar页面的跳转,一个是非tabBar页面的跳转

1.跳转到tabBar页面

使用的代码

html 复制代码
uni.switchTab({})
  • html代码

    html 复制代码
    <template>
    	<view>
    		<view>
    			<button>欣赏小姐姐</button>
    		</view>
    	</view>
    </template>
  • js代码

html 复制代码
<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			// 定义跳转方法
			turn1() {
				// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
				uni.switchTab({
					// person.vue页面路径
					url: "/pages/person/person"
				})
			}
		}
	}
</script>
  • 调用方法
html 复制代码
<template>
	<view>
		<view>
			<button @click="turn1()">欣赏小姐姐</button>
		</view>
	</view>
</template>

完整代码:

html 复制代码
<template>
	<view>
		<view>
			<button @click="turn1()">欣赏小姐姐</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			// 定义跳转方法
			turn1() {
				// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
				uni.switchTab({
					// person.vue页面路径
					url: "/pages/person/person"
				})
			}
		}
	}
</script>

<style>

</style>
  • uni.switchTab(OBJECT)方法的具体讲解可在uni-app官网中查看,在"API"中找到"页面和路由",再找到"uni.switchTab"

2.跳转到非tabBar页面

代码:

html 复制代码
uni.navigateTo({})
  • html代码:
html 复制代码
<template>
	<view>
		<view>
			<button>打开新页面</button>
		</view>
	</view>
</template>
  • js代码:
html 复制代码
<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			// 定义跳转方法
			turn2(){
			    //保留当前页面,跳转到应用内的某个页面
				uni.navigateTo({
                    //new.vue页面路径
					url:"/pages/new/new"
				})
			}
		}
	}
</script>
  • 调用方法
html 复制代码
<template>
	<view>
		<view>
			<button @click="turn2()">打开新页面</button>
		</view>
	</view>
</template>
  • 完整代码

    html 复制代码
    <template>
    	<view>
    		<view>
    			<button @click="turn2()">打开新页面</button>
    		</view>
    	</view>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				
    			}
    		},
    		methods: {
                // 定义跳转方法
    			turn2(){
                     //保留当前页面,跳转到应用内的某个页面
    				uni.navigateTo({
                        //new.vue页面路径
    					url:"/pages/new/new"
    				})
    			}
    		}
    	}
    </script>
    
    <style>
    
    </style>
  • uni.navigateTo(OBJECT)方法的具体讲解可在uni-app官网中查看,在"API"中找到"页面和路由",再找到"uni.navigateTo"

相关推荐
说私域3 小时前
基于开源AI智能客服、AI智能名片与S2B2C商城小程序的微商服务优化及复购转介绍提升策略研究
人工智能·小程序
熬耶16 小时前
Uniapp之微信小程序自定义底部导航栏形态
微信小程序·小程序·uni-app
IT毕设实战小研19 小时前
基于Spring Boot校园二手交易平台系统设计与实现 二手交易系统 交易平台小程序
java·数据库·vue.js·spring boot·后端·小程序·课程设计
weixin_1772972206921 小时前
剧本杀小程序系统开发:重构推理娱乐生态
小程序·重构·娱乐
IT毕设实战小研1 天前
基于SpringBoot的救援物资管理系统 受灾应急物资管理系统 物资管理小程序
java·开发语言·vue.js·spring boot·小程序·毕业设计·课程设计
程序员陆通3 天前
零基础AI编程开发微信小程序赚流量主广告实战
微信小程序·小程序·ai编程
paopaokaka_luck3 天前
校园快递小程序(腾讯地图API、二维码识别、Echarts图形化分析)
vue.js·spring boot·后端·小程序·uni-app
头发还在的女程序员3 天前
ThinkPHP+Mysql 灵活用工小程序-技术深度解析与实践指南
数据库·mysql·小程序
编程猪猪侠3 天前
解决uni-app微信小程序编译报错:unexpected character `1`
微信小程序·小程序·uni-app
2501_915909063 天前
iOS 签名证书全生命周期实战,从开发到上架的多阶段应用
android·ios·小程序·https·uni-app·iphone·webview