小程序中的页面跳转

小程序中的页面跳转

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

相关推荐
星光一影8 小时前
美容/心理咨询/问诊/法律咨询/牙医预约/线上线下预约/牙医行业通用医疗预约咨询小程序
mysql·小程序·vue·php·uniapp
游戏开发爱好者89 小时前
H5 混合应用加密 Web 资源暴露到 IPA 层防护的完整技术方案
android·前端·ios·小程序·uni-app·iphone·webview
2501_915106329 小时前
最新版本iOS系统设备管理功能全面指南
android·macos·ios·小程序·uni-app·cocoa·iphone
游戏开发爱好者810 小时前
HTTPS DDoS 排查 异常流量到抓包分析
网络协议·ios·小程序·https·uni-app·iphone·ddos
jay神10 小时前
【原创】基于小程序的图书馆座位预约系统
微信小程序·小程序·毕业设计·图书馆自习室座位预约系统·座位预约系统
一点晖光10 小时前
小程序中web-view加载uni-app H5如何使用postMessage方法的解决方案
前端·小程序·uni-app
2501_9159184111 小时前
iOS 性能监控 运行时指标与系统行为的多工具协同方案
android·macos·ios·小程序·uni-app·cocoa·iphone
00后程序员张11 小时前
IPA 混淆技术全解,从成品包结构出发的 iOS 应用安全实践与工具组合
android·安全·ios·小程序·uni-app·cocoa·iphone
veteranJayBrother12 小时前
适配小程序的下滑上滑播放视频组件
小程序·apache·音视频
2501_9160088912 小时前
IOScer 证书到底是什么和怎么使用的完整说明
android·ios·小程序·https·uni-app·iphone·webview