uni-app之 声明式导航,编程式导航

uni-app之 声明式导航

uni-app之 声明式导航 跳转

跳转到普通页面

		<navigator url="../detail/detail">跳转到详情</navigator>
		<navigator url="../test/test">跳转到test</navigator>

跳转到 tabbar页面

  • 需要添加这个属性:open-type="switchTab"
		<navigator url="../index/index" open-type="switchTab">跳转到首页</navigator>
		<navigator url="../about/about" open-type="switchTab">跳转到about</navigator>

open-type 相关值

redirect
  • redirect
    • 就是关闭当前页面(页面已卸载),然后跳转到url设置的页面,不存在上一个页面 记录
<navigator url="../detail/detail" open-type="redirect">跳转到详情</navigator>
  • 效果
    在这里插入图片描述

uni-app之 声明式导航 传参

url方法传递参数

<template>
	<view>
			<navigator url="../detail/detail?id=100&name=pink">跳转到详情</navigator>
<!-- 		<button @click="goDetail">跳转到详情</button>
		<button type="default" @click="goDetail2">跳转到详情</button> -->
	</view>
</template>

<script>
	export default {
		data(){
			return {
			}
		},	
		methods: {
		},
	}
</script>
  • 效果
    在这里插入图片描述

页面 拿到传递的参数数据

<template>
	<view>
		<view class="box3">
			我是box3 详情
		</view>
	</view>
</template>
<script>
	export default {
		data(){
			return {
			}
		},	
		methods: {
		},
		onLoad(options){
			console.log("页面加载 options",options);
		}
	}
</script>
  • 效果
    在这里插入图片描述

uni-app之 编程式导航

uni-app之 编程式导航 跳转

uni.navigateTo(OBJECT)

  • 保留当前页面,跳转到应用内的某个页面,使用uni.navigateBack可以返回到原页面。
<template>
	<view>
		<button @click="goDetail">跳转到详情</button>
	</view>
</template>

<script>
	export default {
		data(){
			return {
			}
		},	
		methods: {
			goDetail(){
				uni.navigateTo({
					url:"../detail/detail",
					animationType: 'pop-in',
				})
			},
		},
	}
</script>
  • 效果
    • 跳转到详情页之中

uni.switchTab(OBJECT)

  • 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
<template>
	<view>
		<view class="box3">
			我是box3 详情
		</view>
		<button type="default" @click="goAbout">跳转到about</button>
	</view>
</template>
<script>
	export default {
		data(){
			return {
			}
		},	
		methods: {
			goAbout(){
				uni.switchTab({
					url:"../about/about",
				})
			},
		},
		onUnload(){
			console.log("详情页 卸载");
		}
	}
</script>
  • 效果
  • 从详情页之中,点击跳转到 about,由于about为 tabbar组件的页面,然而详情页非 tabbar,所有会卸载非tabbar的页面

uni.redirectTo(OBJECT)

  • 关闭当前页面,跳转到应用内的某个页面。
<template>
	<view>
		<button type="default" @click="goDetail2">跳转到详情</button>
	</view>
</template>

<script>
	export default {
		data(){
			return {
			}
		},	
		methods: {
			goDetail2(){
				uni.redirectTo({
					url:"../detail/detail",
				})
			}
		},
		onUnload(){
			console.log("msg 卸载");
		}
	}
</script>
  • 效果
    • 跳转到详情页的时候,当前msg页面会被关闭,也就是卸载了,会触发 onUnload 函数

编程式导航 传参

当前页面,跳转到下一个页面,传递参数值

<template>
	<view>
 		<button @click="goDetail">跳转到详情</button>
	</view>
</template>

<script>
	export default {
		data(){
			return {
			}
		},	
		methods: {
			goDetail(){
				uni.navigateTo({
					url:"../detail/detail?id=10&name=ppp"
				})
			}
		},
	}
</script>
  • 效果
    在这里插入图片描述

跳转到页面后,获取传递的参数

<template>
	<view>
		<view class="box3">
			我是box3 详情
		</view>
	</view>
</template>
<script>
	export default {
		data(){
			return {
			}
		},	
		methods: {
		},
		onLoad(options){
			console.log("页面加载-options", options);
		}
	}
</script>
  • 效果
    在这里插入图片描述
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值